0

我们正在尝试使用 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");
           }

任何帮助表示赞赏

4

1 回答 1

0

问题已解决。似乎只需要添加一个检查文件是否物理存在。

if(Sytem.IO.File.FileExists(Server.MapPath(t.FileName))
{

  zip.AddFile(Server.MapPath(t.FileName),"CVs");
}
于 2021-12-19T18:07:46.860 回答