使用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.
-
在ZipFile类中使用using()子句;它是IDisposable的.
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.