we are trying to save zip file using C# Ionic zip library. but it seems to be giving error that the file is not found.
System.IO.FileNotFoundException: 'Could not find file 'PhysicalPath\JobPortal\Job\DownLoadSelectedFiles'.'
the code is as under:
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");
}
any help appreciated
CodePudding user response:
The issue has been resolved. seems just needed to add a check if the file physically was present or not.
if(Sytem.IO.File.FileExists(Server.MapPath(t.FileName))
{
zip.AddFile(Server.MapPath(t.FileName),"CVs");
}