简体   繁体   中英

c# zip file creation raising error file not found

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

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");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM