简体   繁体   English

使用ionic.zip和C#提取文件后解锁zip文件

[英]Unlock zip file after extracting files using ionic.zip and C#

I tried to use the files inside a zip unlocked with ionic.zip in C# 我试图在C#中使用ionic.zip解锁的zip文件中使用的文件

I do that using 我这样做

 string zipToUnpack = filename;
 ExtractFileToDirectory(filename,appPath);

First time it works fine, but then I try a second time and I get an IO exception saying the file is been used by another user. 第一次运行正常,但随后我尝试第二次,但出现IO异常,表示该文件已被其他用户使用。 How can I unlocked this file from the current process? 如何从当前进程中解锁此文件?

I cannot seem to find ExtractFileToDirectory in Ionic.Zip's reference documentation . 我似乎在Ionic.Zip的参考文档中找不到ExtractFileToDirectory I did find a function with the same name in another StackOverflow question, "Extract a ZIP file programmatically by DotNetZip library?" 我确实在另一个StackOverflow问题中找到了一个具有相同名称的函数, “通过DotNetZip库以编程方式提取ZIP文件?” . If that is the implementation that you are using, you probably need to call Dispose on the ZipFile to close the underlying file streams. 如果这是您正在使用的实现,则可能需要在ZipFile上调用Dispose以关闭基础文件流。

public void ExtractFileToDirectory(string zipFileName, string outputDirectory)
{
     using (ZipFile zip = ZipFile.Read(zipFileName))
     {
         Directory.CreateDirectory(outputDirectory);
         zip.ExtractAll(outputDirectory,ExtractExistingFileAction.OverwriteSilently);
     }
}

If not, share more details about how you are extracting the files. 如果没有,请共享有关如何提取文件的更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM