使用Windowsbase dll解压缩 [英] Unzip using Windowsbase dll
本文介绍了使用Windowsbase dll解压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
海,
我已经完成使用Windowsbase dll的压缩.现在,我想使用相同的dll解压缩.我将上传zip文件,并且应该将其解压缩到服务器中.
在此先感谢
Hai,
I have done Zipping using Windowsbase dll. Now I want to do Unzipping using the same dll. I will upload the zip file and it should unzip into the server.
Thanks in advance,
推荐答案
我在我的一个应用程序中使用了此代码
I use this code in one of my applications
public void UnZip(string pathToZipFile, string destinationPath)
{
try
{
using (Package package = ZipPackage.Open(pathToZipFile, FileMode.Open, FileAccess.Read))
{
foreach (PackagePart part in package.GetParts())
{
var target = Path.GetFullPath(Path.Combine(destinationPath, part.Uri.OriginalString.TrimStart('/')));
var targetDir = target.Remove(target.LastIndexOf('\\'));
if (!Directory.Exists(targetDir))
Directory.CreateDirectory(targetDir);
using (Stream source = part.GetStream(FileMode.Open, FileAccess.Read))
{
source.CopyTo(File.OpenWrite(target));
}
}
}
}
catch (Exception ex)
{
throw new Exception(ex.Message + " (Event: UnZip)");
}
}
如果您想查看我的完整代码,可以在我的博客>上找到它. http://perschluter.com/creating-zip-files-in-c-sharp/ [ ^ ]
If you want to see my complete code, you can find it on my blog > http://perschluter.com/creating-zip-files-in-c-sharp/[^]
这篇关于使用Windowsbase dll解压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文