Add file to ZIP with different name

Feb 28, 2012 at 3:09 PM


is it possible to add files to a zip with the name that i want?

I have 3 files: a, b and c.

I add them to zip and stream directly to response.output. In the zipfile they are then called a,b and c. But i want to give them custom names...i dont want the files in the zipfile to be named a,b and c, i want them to be named x,y and z.

Is that possible?

That doesnt work:


var entry = zip.AddFile("a.pdf");

entry.FileName = "x.pdf";

Is there a way to do that?

 I have to directly stream the zipfile, so creating it and then updating and renaming is no option.

Sorry for my bad english! Thanks in advance!

Mar 2, 2012 at 7:12 AM
Edited Mar 2, 2012 at 7:15 AM

Try this code

using (ZipFile zip = new ZipFile())

                string path = @"C:\Test\SQLQuery2.sql";
                string extension= Path.GetExtension(path);
                var zipped= zip.AddFile(path, "files");
                zipped.FileName = "foobar" + extension;

I think entry.FileName should work.

Please share more code in case if does not solved.