-2

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);
Bombacinka
  • 11
  • 2
  • 1
    I don't see any mention of "myappsolution.exe" in your posted code. Please [edit] your post with a [mre]. – gunr2171 Jun 12 '22 at 21:56
  • Have you used the tools provided to you in Windows to lookup which process is using that file? – gunr2171 Jun 12 '22 at 21:57
  • @gunr2171 well myaapsolution.exe is basically the exe visual studio runs when I press f5 like source\repos\Updater\Updater\bin\Debug\Updater.exe – Bombacinka Jun 12 '22 at 22:11

1 Answers1

1

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);
J.Memisevic
  • 429
  • 4
  • 11