上传多个文件&创建拉链

时间:2015-02-02 18:58:51

标签: c# asp.net file-upload filepath dotnetzip

我设法成功上传了两种文件&将相应的文件路径存储在数据库中。现在,我还想创建一个附有两个文件的zip。

我在这个特定的网页上引用了有关zip文件和代码的代码。文件上传 http://www.c-sharpcorner.com/uploadfile/5089e0/how-to-create-zip-in-asp-net-using-c-sharp/

单击“提交”按钮后,将抛出“找不到文件”异常。 Ionic.Zip.dll中出现“System.IO.FileNotFoundException”类型的异常,但未在用户代码中处理

其他信息:C:\ Users \ seldarine \ Desktop \ Proj \ PP_PJ \ PP_Project \ SFiles \ Submissions \ blueteam \ MyCodesF.zip

在此特定行抛出异常 - objZip.Save(Path.Combine(serverFilePath,zipName));

以下是我的代码的一部分:

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

            .....

3 个答案:

答案 0 :(得分:0)

尝试在崩溃的上面添加另一行,看看是否可以调试它以及得到的结果:

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

您可能还想尝试将savePath变量更改为c:\ temp \ test.zip,并查看是否有效。

var savePath = "c:\\temp\\test.zip";

答案 1 :(得分:0)

我觉得您需要Embed DotNetZip into your application才能解决问题:

答案 2 :(得分:0)

确保运行服务器的用户具有该文件夹的写访问权限(serverFilePath)。