开发者

Problem with extracting files with DotNetZip. It doesn't extract files. what's the problem?

开发者 https://www.devze.com 2023-02-11 00:16 出处:网络
private void ZipExtract(string zipfilename) { var path = Server.MapPath(@\"~/Files\"); ZipFile zip = ZipFile.Read(zipfilename);
private void ZipExtract(string zipfilename)
{
    var path = Server.MapPath(@"~/Files");
    ZipFile zip = ZipFile.Read(zipfilename);
    zip.ExtractSelectedEnt开发者_如何学Gories("name=*.jpg,*.jpeg,*.png,*.gif,*.bmp", " ", path,ExtractExistingFileAction.OverwriteSilently);
}


[HttpPost]
public ContentResult Uploadify(HttpPostedFileBase filedata)
{
    var path = Server.MapPath(@"~/Files");
    var filePath = Path.Combine(path, filedata.FileName);
    if (filedata.FileName.Contains(".zip"))
    {
        ZipExtract(filedata.FileName);
    }
    filedata.SaveAs(filePath);
}


what's the error you see? Exception? Other condition? You need to add some additional context to your question. But there are a couple things that stick out even without a better description.

  1. employ a using() clause with the ZipFile class; it is IDisposable.

  2. It looks like you try to extract the zip file before you call .SaveAs(). If I read your code correctly, that means the ZipFile.Read() is trying to read a file that has not yet been created. If that is the case it will throw a FileNotFoundException. I may be wrong about this; more text from you would help clarify.

0

精彩评论

暂无评论...
验证码 换一张
取 消