0

I managed to upload two kinds of files successfully & store the respective filepaths on the database. Now,I'd also like to create a zip with both files attached to it.

I referenced the codes to this particular webpage regarding zip files & file uploads http://www.c-sharpcorner.com/uploadfile/5089e0/how-to-create-zip-in-asp-net-using-c-sharp/

Upon clicking the submit button, a File Not Found exception is thrown. An exception of type 'System.IO.FileNotFoundException' occurred in Ionic.Zip.dll but was not handled in user code

Additional information: C:\Users\seldarine\Desktop\Proj\PP_PJ\PP_Project\SFiles\Submissions\blueteam\MyCodesF.zip

The exception is thrown at this particular line - objZip.Save(Path.Combine(serverFilePath,zipName));

Here are a portion of my codes :

  protected void btn_submit_Click(object sender, EventArgs e)
    {
        string input = "";
        string pp, vv,zip;
        string extPp, extVv;

        if (f_slide.HasFile && f_video.HasFile)
        {
            //Get file name & extensions
            pp = Path.GetFileName(f_slide.PostedFile.FileName);
            extPp = Path.GetExtension(pp);
            vv = Path.GetFileName(f_video.PostedFile.FileName);
            extVv = Path.GetExtension(vv);

            string user = Session["userid"].ToString();
            //where zip name is named after the username (current user)  logged in
            string zipName = user + ".zip";

            //To save to folders
            string filePath = "SFiles/Submissions/" + user + "/";
            string serverFilePath = Server.MapPath(filePath);

            //If directory does not exist
            if (!Directory.Exists(serverFilePath))
            { // if it doesn't exist, create
                System.IO.Directory.CreateDirectory(serverFilePath);
            }

            //****To create zip file*****
            using(ZipFile objZip = new ZipFile())
            {
                string zipSlidePath = Path.Combine(serverFilePath,pp);
                string zipVideoPath = Path.Combine(serverFilePath,vv);
                objZip.AddFile(zipSlidePath);
                objZip.AddFile(zipVideoPath);
                ***objZip.Save(Path.Combine(serverFilePath,zipName));***
            }

            //Store files
            f_slides.SaveAs(Path.Combine(serverFilePath, pp));
            f_video.SaveAs(Path.Combine(serverFilePath, vv));

            .....
Enovyne
  • 195
  • 1
  • 7
  • 20

2 Answers2

0

Try adding another line above the crashing one and see if you can debug it and what result you get:

var savePath = Path.Combine(serverFilePath,zipName +".zip"); 

You might also want to try changing the savePath variable to something like c:\temp\test.zip and see if that works.

var savePath = "c:\\temp\\test.zip";
Sameer Alibhai
  • 3,092
  • 4
  • 36
  • 36
0

Make sure the user under which the server is running has write access to that folder (serverFilePath).

Mihai Caracostea
  • 8,336
  • 4
  • 27
  • 46