使用DotNetZip提取文件时出现问题.它不会解压缩文件.有什么问题? [英] Problem with extracting files with DotNetZip. It doesn't extract files. what's the problem?

查看:81
本文介绍了使用DotNetZip提取文件时出现问题.它不会解压缩文件.有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void ZipExtract(string zipfilename)
{
    var path = Server.MapPath(@"~/Files");
    ZipFile zip = ZipFile.Read(zipfilename);
    zip.ExtractSelectedEntries("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. 在ZipFile类中使用using()子句;它是IDisposable的.

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

似乎您尝试在调用.SaveAs()之前解压缩zip文件.如果我正确阅读了您的代码,则意味着ZipFile.Read()正在尝试读取尚未创建的文件.如果是这种情况,它将抛出一个 FileNotFoundException .我对此可能是错的.您提供的更多文字将有助于澄清.

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.

这篇关于使用DotNetZip提取文件时出现问题.它不会解压缩文件.有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆