当我在 zip 中保存多个文件时,出现此错误“无法访问已关闭的文件”。这是代码。错误在zip.Save(NewZipPath);
internal static string UpdateZipFile(string PdfPath, string ZipPath,
string NewZipPath, string docPath)
{
try
{
using (ZipFile zip = ZipFile.Read(ZipPath))
{
FileStream fs = new FileStream(PdfPath, FileMode.Open, FileAccess.Read);
DirectoryInfo Dir = new DirectoryInfo(docPath);
FileInfo[] FileList = Dir.GetFiles("*.*", SearchOption.AllDirectories);
foreach (FileInfo FI in FileList)
{
zip.AddEntry(FI.FullName, fs);
}
// Error at this line if more than one
// files in above directory.
zip.Save(NewZipPath);
fs.Close();
fs.Dispose();
return "- ZIP Generated Successfully !";
}
}
catch (Exception ex)
{
return ex.Message;
}
}
完全例外
System.ObjectDisposedException: Cannot access a closed file.
at System.IO.__Error.FileNotOpen()
at System.IO.FileStream.get_Length()
at Ionic.Zip.ZipEntry.SetInputAndFigureFileLength(Stream& input)
at Ionic.Zip.ZipEntry._WriteEntryData(Stream s)
at Ionic.Zip.ZipEntry._EmitOne(Stream outstream)
at Ionic.Zip.ZipEntry.Write(Stream s)
at Ionic.Zip.ZipFile.Save()
at Ionic.Zip.ZipFile.Save(String fileName)
at RideShare.Utility.UpdateZipFile(String PdfPath,
String ZipPath, String NewZipPath, String docPath) in
谢谢。