我們正在嘗試使用 C# Ionic 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");
}
任何幫助表示贊賞
uj5u.com熱心網友回復:
問題已解決。似乎只需要添加檢查檔案是否物理存在。
if(Sytem.IO.File.FileExists(Server.MapPath(t.FileName))
{
zip.AddFile(Server.MapPath(t.FileName),"CVs");
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/390887.html
標籤:C# asp.net-mvc 离子拉链
上一篇:標題內容型別應該做什么?
