I'm using the DotNetZip library to extract files from a zip file.
using(ZipFile zip = ZipFile.Read(zipLocation))
{
foreach (ZipEntry entry in zip){
entry.Extract(_updateDir);
Log.Write("Unpacked: " + entry.FileName, Log.LogType.Info);
}
zip.Dispose();
}
Later on, I attempt to edit one of the files that I extracted.
var updateList = allFiles.Where(x => x.Contains(".UPD"));
foreach (string upd in updateList){
string[] result = File.ReadAllLines(upd);
int index = Array.IndexOf(result, "[Info]");
//then I do stuff with index
}
At the line
string[] result = File.ReadAllLines(upd);
I get the exception: The process cannot access the file <file name> because it is being used by another process.
I know that this exception is being thrown because the file is in use elsewhere. The only place it is in use before File.ReadAllLines(upd)
is in the DotNetZip code above.
Is there a way in the DotNetZip code to prevent this from happening?