Bino
Bino

Reputation: 904

Zip a folder with specified path separator that will work in windows and Linux using dotnetzip library

When i am zipping a folder with DotNetZip, it working properly, but when unzipping the zipped folder in Linux based server it is not working. The server team told me that While zipping the file use ‘/’ instead of ‘\’ as our system is Linux based.

How can i mention a path separator when zipping folder with DotNetZip?

Below is the code for zipping my folder.

ZipFile zp = new ZipFile();
            zipfileName = Server.MapPath("~/folder") + @"/" + folderName + @".zip";


            if (Directory.Exists(directoryPath))
            {
                zp.AddDirectory(directoryPath, folderName);
                zp.Save(zipfileName);
            }

Upvotes: 1

Views: 716

Answers (1)

Bino
Bino

Reputation: 904

I found the answer. I changed my code as below, its working now.

Ionic.Zip.ZipFile zp = new Ionic.Zip.ZipFile(); 
zp.AlternateEncodingUsage = ZipOption.Always;
zp.AlternateEncoding = Encoding.UTF8;
zp.AddDirectory(directoryPath, folderName);
zp.Save(zipfileWithPathAndName);

Upvotes: 1

Related Questions