0

I tried to use the files inside a zip unlocked with ionic.zip in C#

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. How can I unlocked this file from the current process?

4

1 回答 1

4

我似乎ExtractFileToDirectoryIonic.Zip 的参考文档中找不到。我确实在另一个 StackOverflow 问题中找到了一个同名的函数,“通过 DotNetZip 库以编程方式提取 ZIP 文件?” . Dispose如果这是您正在使用的实现,您可能需要调用ZipFile关闭底层文件流。

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

如果没有,请分享有关如何提取文件的更多详细信息。

于 2013-05-22T07:21:04.650 回答