[英]c# zip file creation raising error file not found
我们正在尝试使用 C# 离子 zip 库保存 zip 文件。 但似乎给出了找不到文件的错误。
System.IO.FileNotFoundException: 'Could not find file 'PhysicalPath\JobPortal\Job\DownLoadSelectedFiles'.'
代码如下:
public ActionResult DownLoadSelectedFiles(string applicantIds)
{
List<ApplicantList> listapplicant = _applicantBl.GetFileNames(applicantIds);
MemoryStream ms = new MemoryStream();
using (ZipFile zip = new ZipFile())
{
foreach (ApplicantList t in listapplicant)
{
//t.FileName is relative path
zip.AddFile(Server.MapPath(t.FileName),"CVs");
}
zip.Save(ms); // this line generates error
}
ms.Seek(0, SeekOrigin.Begin);
return File(ms.ToArray(), "application/zip");
}
任何帮助表示赞赏
问题已解决。 似乎只需要添加一个检查文件是否物理存在。
if(Sytem.IO.File.FileExists(Server.MapPath(t.FileName))
{
zip.AddFile(Server.MapPath(t.FileName),"CVs");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.