app.exe is used by another process while extracting zip

58 Views Asked by At

When I try to extract my zip that I just downloaded from server I get System.IO.IOException Process cant access file "myappsolution".exe because it is used by another process.

WebClient webClient = new WebClient();
            var client = new WebClient();
            System.Threading.Thread.Sleep(5000);
            client.DownloadFile("server", @"myzip.zip");
            FastZip fastZip = new FastZip();
            ZipStrings.CodePage = (Encoding.GetEncoding(System.Globalization.CultureInfo.CurrentCulture.TextInfo.OEMCodePage).CodePage);
            fastZip.ExtractZip(zipPath, extractPath, null);
1

There are 1 best solutions below

0
J.Memisevic On

Your web client is not disposed by the time when your FastZip is trying to access file. Try something like this

using (WebClient client= new WebClient())
{
    client.DownloadFile("server", @"myzip.zip");
}

FastZip fastZip = new FastZip();
ZipStrings.CodePage = 

(Encoding.GetEncoding(System.Globalization.CultureInfo.CurrentCulture.TextInfo.OEMCodePage).CodePage);
fastZip.ExtractZip(zipPath, extractPath, null);