【发布时间】:2013-07-09 07:33:20
【问题描述】:
我在 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");
}
}
【问题讨论】:
-
尝试指定Hello.csv的完整路径
-
这是一个动态创建的文件。
-
我不确定ZipFile类是这样使用的,看这里msdn.microsoft.com/en-us/library/… PS:链接已编辑,现在是engspan>
-
@WannyMiarelli:可能是另一个类(可能是 DotNetZip)。
-
@JeffRSon 我认为是这样,但未指定。告诉我们您正在使用什么库,它会有所帮助。
标签: c# .net windows-services filenotfoundexception