WebClient.DownloadFile Hangs On Certain Files

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mcfly1204
    New Member
    • Jul 2007
    • 233

    #1

    WebClient.DownloadFile Hangs On Certain Files

    We are using the DownloadFile method of the WebClient class to download artwork via URLs for purchase orders, this works well for the most part, but hangs with certain file types. We never have problems with .pdf files, but .ai files (Illustrator) just hang with 0 bytes being downloaded, and then eventually times out after the default 60 seconds. Has anyone experienced similar activity while downloading files with the WebClient class? Keep in mind that the files that are being downloaded are hosted on the same server, in the same directory.

    Code:
    if (validURL == true)
            {
                    WebClient client = new WebClient();
    
                    try
                    {
                            client.Headers.Add("Accept: text/html, application/xhtml+xml, */*");
                            client.Headers.Add("user-agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)");
                            client.DownloadFile(url, Path);
                     }
                     catch (UriFormatException ex)
                     {
                             Console.WriteLine(ex.Message);
                     }                          
             }
  • mcfly1204
    New Member
    • Jul 2007
    • 233

    #2
    I had another method that that was checking the validity of the URLs where I was not closing a web response that was accessing the URL. After adding "response.Close ()", all files are now downloading.

    Comment

    Working...