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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user2407825
  • 1
  • 1
  • 1
  • Welcome to [so]. I'm pretty sure this is what you are really asking for: [Is there a way to check if a file is in use?](http://stackoverflow.com/a/11060322/495455) – Jeremy Thompson May 22 '13 at 03:13
  • Nope, I want to open the same file several times in one instance.. and it doesn't let me after the first time.. – user2407825 May 22 '13 at 03:20
  • Is there a way to force release of file handles or determine if your last call created handles that should be cleared? – Ross Bush May 22 '13 at 03:22
  • @user2407825 yeah, that's because its locked. Another user has an exclusive lock on the file. What you need to do is explicitly release the handle to the open file before the 2nd attempt. Good luck! – Jeremy Thompson May 22 '13 at 03:27
  • 1
    I am looking in the [references](http://dotnetzip.herobo.com/DNZHelp/Index.html) for that method in Iconic.Zip, but I can not find it. Is ExtractFileToDirectory something you wrote? If so it might help if you include the source of that method. – jacob May 22 '13 at 03:27

1 Answers1

4

I cannot seem to find ExtractFileToDirectory in Ionic.Zip's reference documentation. I did find a function with the same name in another StackOverflow question, "Extract a ZIP file programmatically by DotNetZip library?". If that is the implementation that you are using, you probably need to call Dispose on the ZipFile to close the underlying file streams.

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.

Community
  • 1
  • 1
chwarr
  • 6,777
  • 1
  • 30
  • 57
  • thanks c45207, I did got it done yesterday.. I did call Dispose.. it works.. thanks anyways – user2407825 May 22 '13 at 17:51
  • Glad you got it working, @user2407825. Since this answer seems to have been the solution to your question, please consider [accepting](http://stackoverflow.com/help/accepted-answer) it as the solution. (There is a check mark next to it that you can check.) – chwarr Jul 16 '13 at 00:15