2011-02-18 38 views
1
public void ZipExtract(string zipfilename, string outputDirectory) 
{  
    using (ZipFile zip = ZipFile.Read(zipfilename))//file not found exception 
    { 
     Directory.CreateDirectory(outputDirectory); 
     zip.ExtractSelectedEntries("name=*.jpg,*.jpeg,*.png,*.gif,*.bmp", " ", 
      outputDirectory, ExtractExistingFileAction.OverwriteSilently); 
    } 
} 

[HttpPost] 
public ContentResult Uploadify(HttpPostedFileBase filedata) 
{ 
    var path = Server.MapPath(@"~/Files"); 
    var filePath = Path.Combine(path, filedata.FileName); 
    if (filedata.FileName.EndsWith(".zip")) 
    { 
     ZipExtract(filedata.FileName,path); 
    } 
    filedata.SaveAs(filePath); 
    // CreateThumbnail(filePath); 
    _db.Photos.Add(new Photo 
     { 
      Filename = filedata.FileName 
     }); 

    _db.SaveChanges(); 
    return new ContentResult{Content = "1"}; 
} 

我嘗試提取上傳的zip壓縮包,並保存在文件夾中提取文件,但「未找到文件」異常發生的時間。什麼是錯誤?「文件未發現異常」試圖提取zip歸檔與DotNetZip

+0

這是你問同樣的quesiton以前http://stackoverflow.com/questions/5014659和FileNotFound例外的是什麼,我認爲你會看到,在我對前一個問題的回答中。 http://stackoverflow.com/questions/5014659/problem-with-extracting-files-with-dotnetzip-it-doesnt-extract-files-whats-th/5019364#5019364 – Cheeso 2011-02-23 00:41:48

回答

0

您是否嘗試過在此設置斷點,並查看filedata.FileName具有的值? (,看看它是否真正存在於服務器上。)

if (filedata.FileName.EndsWith(".zip")) 
     { 
     ZipExtract(filedata.FileName,path); 
    }