Search code examples
c#dotnetzip

DotNetZip in C# webapp - how to change the name of the zip folder structure


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?


Solution

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