1
votes

this is the code in my app

 Response.ContentType = "application/zip";
            Response.AddHeader("content-disposition", "filename=" + "filename.zip");
            using (ZipFile zip = new ZipFile())
            {
                zip.AddEntry(@"F:\My Pictures\2011\DSC04854.jpg", @"\");
                zip.AddEntry(@"F:\My Pictures\2011\DSC04854.jpg", @"\");
                zip.AddEntry(@"F:\My Pictures\2011\DSC04854.jpg", @"\");
                zip.Save(Response.OutputStream);
            }
            Response.Close();

I would like to create a zip file with a simplified folder structure (namely one folder) that gets written as output.

I have seen some answers to similar questions and I have tried many suggestions however I do not get the desired outcome. This code produces a zip file with the full folder structure.

Can anyone help?

3

3 Answers

1
votes

You are using AddEntry, what you want is AddFile; the 2nd parameter to AddFile (when a string) is the internal directory.

0
votes

When adding the entries to the Zip, the second parameter could be left empty to place the files in the root of the folder.

zip.AddEntry(link_to_file.format, string.Empty);
0
votes

I had the same problem but using zip.AddFiles(filePaths) still create full hierarchical zip file. I come cross another overload that simply solve this problem. just use: zip.AddFiles(filePaths,false,".") the second parameter is > preserve the hierarchical structure the third parameter is the structure you just want to use to produce zip file. using

"." means no nested folder allowed or simply zip on the current folder!