【问题标题】:Error occured in saved zip file+using Ionic.Zip保存的 zip 文件中发生错误+使用 Ionic.Zip
【发布时间】:2014-11-17 11:06:39
【问题描述】:

我有很多文件,我想将它们添加到一个新的 zip 文件中。 我使用了这个命名空间: 使用 Ionic.Zip

这里是我的代码:

 for (int i = 0; i < deliveryList.Count; i++)
                    {
                       // System.IO.MemoryStream st = new System.IO.MemoryStream(x.Data.Data);
                        zip.AddEntry(x.StudentObj.Number.ToString() + '.' + t[t.Length -1 ],x.Data.Data);
}
 zip.Save(Response.OutputStream); //"Archive.zip");

现在当我打开保存的 zip 文件时,出现了这个错误:

C:\Users\Sara\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5\D6IMASPE\TExamGrades.zip: The archive is either in unknown format or damaged

【问题讨论】:

    标签: c# zipfile


    【解决方案1】:

    从我看到的 sn-p 中,我假设 zip 是一个 Ionic.Zip.ZipFile 实例,如果不是,请提供更多信息。

    ZipFile.Save(Stream) 将 写入 流,并且再次 从我从该 sn-p 中看到的看来您正在尝试 写入到响应流,而不是从中读取

    请提供更多信息,我会尽力为您提供进一步帮助。

    【讨论】:

      【解决方案2】:

      您应该尝试从路径而不是流中压缩。

          Dim zip = New Ionic.Zip.ZipFile()
      
          Try
              zip.AddFile(NameFile1,PathFile1)
              zip.AddFile(NameFile2,PathFile2)
              zip.AddFile(NameFile3,PathFile3)
              zip.Save(sZipDestinyPat)
          Catch ex As Exception
              ZipDirectory = -1
          End Try
      

      【讨论】:

        猜你喜欢
        • 2013-02-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-06-22
        • 1970-01-01
        • 2021-02-22
        • 2016-11-26
        • 1970-01-01
        相关资源
        最近更新 更多