i have a folder structure and files in those folders.i have to zip all those files with folder structure.
i found examples which only zip a file not all folder structure. i am working on VS 2008. please suggest me the way to zip files with folder structure with c#
Have you tried DotNetZip ?
You can use it to zip a folder.
actually i dont have to create folders first. it creates folder automatically when i specify files with folder name. and it works with both the links provided. thanks guys
Related
I need some help.
I'm trying to zip 3 files, as I you can see in the image
But i only want to zip the two .pdf files (the name is dynamic) and the xml file.
I want to ignore the others .zip files that exist in that folder.
Anyone knows? Thanks in advance.
Regards.
I am using ZIpstorer class library to compress files. I am able to zip a file by calling zip.AddFile procedure. But I want to zip folders which has subfolders too. So the resulting zip file should have folder and subfolder structure inside the zip file normally. I am not able to do it. if i process each file by looping all folders and sub folders and then if call zip.Addfile then it will result in zip file with all the files inside it without a directory structure.
So how can i zip a folder using Zipstorer class . What changes i have to do?
You can use (back)slashes for the _filenameInZip (sic) parameter to add files in a directory in the zip:
zip.Addfile(,,"directory/filename.txt",);
Or
zip.Addfile(,,"directory\\filename.txt",);
I'm using System.IO and ZipFile, I was wondering if anyone could give me a snippet of code that extracts files from a .zip archive and puts them into a .jar file, or atleast helps get me started with doing something like that.
JARs are ZIPs just with a different extension, just copy and rename the file.
Jar and zip has exactly same format.
You can add meta-inf to that jar if you want to add some manifest (can be done via JarFile etc)
I have an application that upon execution It copies two folders with subfolders that are in the same location to another windows location %AppData%
Now I have the following files :
MyApp.exe , Folder1, Folder2
In each folder there are subfolders. How to embed these two folders as resources inside the application so after compiling the program, I get only one executable file. And when I click on it, it extract the two folders to the same location then do the rest of job.
I know how to add a file as embedded resource then retrieve it using reflection,
but how about a folder Is that even possible??
I had to solve this problem recently. I embedded a ZIP file, and then decompressed it at runtime.
.NET 4.5 includes ZIP functionality. If not, use SharpZipLib or DotNetZip.
I need to combine 3 files into 1 zip file and make it available to download for the user. I am able to achieve my requirement except one thing: it zips the files into the subfolders.
For example, my files are located like the following:
C:\TTCG\WebSites\Health\ABC.CSV
C:\TTCG\WebSites\Health\XYZ.CSV
C:\TTCG\WebSites\Health\123.CSV
But in the zip file, it zip the files in the folder by using "TTCG\WebSites\Health\" as the path. Please see the attach file.
I don't want the folders in the path. I just want 3 files in the zip file without folders. How can I achieve that?
My codes to generate the zip file is as below:
ZipFile z = ZipFile.Create(Server.MapPath("~" + #"\Accident.zip"));
//initialize the file so that it can accept updates
z.BeginUpdate();
//add the file to the zip file
z.Add(Server.MapPath("~" + #"\ABC.csv"));
z.Add(Server.MapPath("~" + #"\XYZ.csv"));
z.Add(Server.MapPath("~" + #"\123.csv"));
//commit the update once we are done
z.CommitUpdate();
//close the file
z.Close();
Based on the FAQ, you have to strip the folder path out manually:
How can I create a Zip file without folders?
Remove the path portion of the filename used to create a ZipEntry
before it is added to a ZipOutputStream
ZipEntry entry = new ZipEntry(Path.GetFileName(fullPath));
The FAQ can be found here.
It seems to be a limitation of the library. Hope this helps!
If you have your files in a FileSystemInfo, you can use: z.Add(file.FullName, Path.GetFileName(file.FullName));
This will add your files in the root directory of your zip.
z.Add(pathToFile, pathInZipFile);