【问题标题】:Zip a folder with specified path separator that will work in windows and Linux using dotnetzip library使用 dotnetzip 库压缩具有指定路径分隔符的文件夹,该文件夹将在 Windows 和 Linux 中工作
【发布时间】:2017-06-13 15:14:01
【问题描述】:

当我使用 DotNetZip 压缩文件夹时,它可以正常工作,但是在基于 Linux 的服务器中解压缩压缩文件夹时,它无法正常工作。服务器团队告诉我,压缩文件时使用“/”而不是“\”,因为我们的系统是基于 Linux 的。

使用 DotNetZip 压缩文件夹时如何提及路径分隔符?

下面是压缩文件夹的代码。

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


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

【问题讨论】:

  • 您是否需要在 zip 文件中添加目录?
  • 我只是想压缩一个传递给保存功能的文件夹。

标签: c# asp.net .net dotnetzip


【解决方案1】:

我找到了答案。我改变了我的代码如下,它现在可以工作了。

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

【讨论】:

  • 你永远不应该使用zipfileName = Server.MapPath("~/folder") + @"/" + folderName + @".zip";,而是使用Path.Combine()
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-24
  • 2015-03-29
  • 1970-01-01
  • 1970-01-01
  • 2011-12-12
  • 1970-01-01
相关资源
最近更新 更多