locked
Downloading a file RRS feed

  • Question

  • Hi I have written this code to download files from server into a local folder.

     

    WebClient client = new WebClient();
                string url = e.CommandArgument.ToString();
    
                string strfileName = url.Substring(url.LastIndexOf(@"\"), url.Length - url.LastIndexOf(@"\"));
    
                client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
    
                client.DownloadFileAsync(new Uri(url), ConfigurationSettings.AppSettings["TempFolderLocation"].ToString() + strfileName.Replace(@"\", ""));
    

    Now I want to show the download status in the form of progressbar for this download. So in order to implement that I have to know a technique through which one has to find out, how much down is completed and how much remaining. So how can I do that?

    Thanks in Advance


    Adeel
    • Moved by Lie You Friday, September 30, 2011 5:50 AM ASP.Net related. (From:Visual C# General)
    Friday, September 23, 2011 9:53 AM

Answers

All replies

  • The DownloadProgressChangedEventArgs of the DownloadProgressChangedEvent has the information you want.
    Friday, September 23, 2011 10:01 AM
  • That works well with Windows form but not with ASPX page
    Adeel
    Friday, September 23, 2011 10:06 AM
  • The solution is as JohnWeim suggest, how to get it properly working in ASP.NET isn't what these forums cover. You can use http://forums.asp.net for help on that.

    Friday, September 23, 2011 10:11 AM
  • Hi Adeel,

    you can use Background worker thread, as it has ProgressChanged event.


    Regards, http://shwetamannjain.blogspot.com
    Friday, September 23, 2011 10:54 AM
  • Hi Adeel,

    you can use Background worker thread, as it has ProgressChanged event.


    Regards, http://shwetamannjain.blogspot.com

    That's not something you want to be doing in an ASP environment...

    Progress bars in web environments (especially for server side processing) are nontrivial.  There are a lot of resources out there on the web (and 3rd party solutions to make it easier on you) but it's not just adding a few lines of code to your solution.

    Friday, September 23, 2011 2:42 PM
  • That works well with Windows form but not with ASPX page
    Adeel

    Why is there any difference?  You didn't ask how to implement a progress indicator, you only asked how to get the info.
    Friday, September 23, 2011 3:05 PM