haf / DotNetZip.Semverd

Please use System.IO.Compression! A fork of the DotNetZip project without signing with a solution that compiles cleanly. This project aims to follow semver to avoid versioning conflicts. DotNetZip is a FAST, FREE class library and toolset for manipulating zip files. Use VB, C# or any .NET language to easily create, extract, or update zip files.
Other
546 stars 218 forks source link

Confused about saving behavior #204

Closed JohnFredMeyer closed 4 years ago

JohnFredMeyer commented 4 years ago

I am confused at behavior i see when saving files. Lets say I want to create a zip of just picture files. Example Folder: C:\Temp Pictures: C:\Temp\pic1.jpg C:\Temp\pic2.jpg C:\Temp\pic3.jpg

Now code:

                    var fileNames = Directory
                        .GetFiles(@"C:\Temp\");

                    using (var zipFile = new ZipFile())
                    {
                        zipFile.AddFiles(fileNames);
                        zipFile.Save(streamToReturn);
                    }

This works and produces zip but when I open archive it starts with TEMP folder even though I don't want folder. I just want zip file with three pictures. I have tried saving to file, stream then to file etc and cannot seem to get that behavior. Any ideas?

JohnFredMeyer commented 4 years ago

Sorry should have dug around more after looking at more closely there is a way to pass direcotryPathInArchive.

This fixes.

        using (var zipFile = new ZipFile())
        {

            zipFile.AddFiles(fileNames, "");
            zipFile.Save(savedZipFilePath);
        }