【发布时间】:2015-02-02 18:58:51
【问题描述】:
我成功上传了两种文件并将各自的文件路径存储在数据库中。现在,我还想创建一个附有两个文件的 zip。
我在这个特定网页上引用了有关 zip 文件和文件上传的代码 http://www.c-sharpcorner.com/uploadfile/5089e0/how-to-create-zip-in-asp-net-using-c-sharp/
单击提交按钮后,会引发 File Not Found 异常。 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));
.....
【问题讨论】:
-
您发布的文件是否真的存储在这里:“SFiles/Submissions/”+用户+“/”?
-
是的,文件存储在那里。我觉得语法有问题,在抛出异常的那一行。
标签: c# asp.net file-upload filepath dotnetzip