Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 上载多个文件并创建zip_C#_Asp.net_File Upload_Filepath_Dotnetzip - Fatal编程技术网

C# 上载多个文件并创建zip

C# 上载多个文件并创建zip,c#,asp.net,file-upload,filepath,dotnetzip,C#,Asp.net,File Upload,Filepath,Dotnetzip,我成功地上传了两种文件&将各自的文件路径存储在数据库中。现在,我还想创建一个包含两个文件的zip 我引用了关于zip文件和文件上传的特定网页的代码 单击“提交”按钮后,将引发“未找到文件”异常。 Ionic.Zip.dll中发生“System.IO.FileNotFoundException”类型的异常,但未在用户代码中处理 其他信息:C:\Users\seldarine\Desktop\Proj\PP\u PJ\PP\u Project\SFiles\Submissions\blueteam

我成功地上传了两种文件&将各自的文件路径存储在数据库中。现在,我还想创建一个包含两个文件的zip

我引用了关于zip文件和文件上传的特定网页的代码

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

其他信息:C:\Users\seldarine\Desktop\Proj\PP\u PJ\PP\u Project\SFiles\Submissions\blueteam\MyCodesF.zip

在这一行抛出异常-objZip.SavePath.CombineserverFilePath,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));

            .....

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

var savePath = Path.Combine(serverFilePath,zipName +".zip"); 
您可能还想尝试将savePath变量更改为c:\temp\test.zip之类的值,看看是否有效

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

我觉得您需要解决这个问题:

确保运行服务器的用户对该文件夹serverFilePath具有写入权限。

同样的异常结果。异常:抛出:System.IO.filenotfoundexception您可以发布异常的全部文本吗?您发布的文件是否真的存储在这里:SFiles/Submissions/+user+/?是的,文件存储在那里。我觉得抛出异常的那一行的语法有问题。