Click here to Skip to main content
15,876,991 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I keep getting this error:

Line 24:         WebClient client = new WebClient();
Line 25:         client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
Line 26:         client.DownloadFileAsync(new Uri(url), @"c:\");
Line 27:     }
Line 28: 

this is my code:

protected void dl001_Click(object sender, EventArgs e){
    string url = @"File.doc";
    WebClient client = new WebClient();
    client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
    client.DownloadFileAsync(new Uri(url), @"c:\");

can somebody share me his comment? Thanks a lot. :)
Updated 28-Oct-12 3:09am

Both the URL and the local file are incomplete.

The URL should be something like "htpp://" and the local file @"C:\DownloadedFile.doc".

The behavior of the URL differs when the BaseAddress[^] is not empty as described in remarks section of WebClient.DownloadFileAsync Method (Uri, String)[^].
Quote: Remarks
If the BaseAddress property is not an empty string ("") and address does not specify an absolute URI, address must be a relative URI that is combined with BaseAddress to form the absolute URI of the requested data.
Share this answer
after amending the code i received this error:

Asynchronous operations are not allowed in this context. Page starting an asynchronous operation has to have the Async attribute set to true and an asynchronous operation can only be started on a page prior to PreRenderComplete event.
Share this answer
Thomas Daniels 28-Oct-12 10:28am    
Then use DownloadFile instead of DownloadFileAsync
Thanks for your help it works!
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900