我在 Windows 服务中编写了以下代码。当我尝试保存 zip 文件时,我收到了 File Not Found 异常。我在zipFile.AddFile
.
System.IO.MemoryStream ms1 = new System.IO.MemoryStream();
System.IO.StreamWriter writer = new System.IO.StreamWriter(ms1, Encoding.UTF8);
string strHeader = "";
if (FailedErrorLogList != null && FailedErrorLogList.Any())
{
strHeader += "file_name" + ",";
strHeader += "mobile_no" + ",";
strHeader += "Description" + ",";
writer.WriteLine(strHeader);
foreach (Transactionapierrorfailedlog ErrorLog in FailedErrorLogList)
{
string strRowValue = "";
strRowValue += Escape(ErrorLog.file_name) + ",";
strRowValue += Escape(ErrorLog.mobile_no) + ",";
strRowValue += Escape(ErrorLog.Description) + ",";
writer.WriteLine(strRowValue);
// writer2.WriteLine(strRowValue);
}
writer.Flush();
ms1.Position = 0;
}
String filename = "Hello.csv";
if (FailedErrorLogList != null && FailedErrorLogList.Any())
{
ZipFile zipFile = new ZipFile();
using (zipFile)
{
zipFile.AddFile(filename);
zipFile.Save("Hello.zip");
}
}