Pdk
Pdk

Reputation: 53

File download from http site fails with error, "System.IO.IOException'

File download from HTTP site fails with error,

"System.IO.IOException: The process cannot access the file 'c:\temp\python-3.8.0-amd64.exe' because it is being used by another process".

url = "http://ip:43/installer/python-3.8.0-amd64.exe"
Uri uri = new Uri(url);
filename = uri.Segments[uri.Segments.Length - 1];
installer_path = $@"c:\Temp\{filename}";

using (var client = new WebClient())
{
   client.DownloadFile(url, installer_path);
   client.Dispose();
}

Upvotes: 1

Views: 269

Answers (2)

bimal george
bimal george

Reputation: 313

  1. check if the file available on the location
  2. Check MIME configuration in IIS
  3. Check the access rights to the destination also
client.DownloadFileCompleted += WcOnDownloadFileCompleted;

private static void WcOnDownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
    if (!e.Cancelled && e.Error == null)
    {
        //async download completed successfully
    }
    handle.Set(); // in both the case let the void main() know that async event had finished so that i can quit
}

Upvotes: 1

Abhijeet Talele
Abhijeet Talele

Reputation: 26

  1. Open Task manager
  2. Go To Processes Tabs
  3. Search for "python-3.8.0-amd64.exe" in list
  4. If its there then right click on it and select End Task
  5. Now run your code, it should be fine

Upvotes: 0

Related Questions