none
How to down load file from web without "Save As" dialog pop out? RRS feed

  • 问题

  • Hi All,

    Now I'd like to implement a function that dowloading file from web without "Save As" dialog pop out. In other words, if the function receive the parameter "FileUri" and "LocalPath", the files can be downloaded smoothly. I use the method "WebBrowser.Navigate(FileUri)", but it needs I select the local path manually, which is not expected! How to do it

    Thanks!

    BRs.

    ZengWei

    2012年2月8日 6:33

全部回复

  • Hi Zeng Wei,

      It seems that you have to set the parameter named FileUri due to its menthod reqirement,and you want to use WebRequest object to do the next work. Here are some useful code samples  listed as follows:

    MyDownloader: A Multi-thread C# Segmented Download Manager

    http://www.codeproject.com/Articles/21053/MyDownloader-A-Multi-thread-C-Segmented-Download-M

      If you want to get the more information about downloading web page as file on Microsoft ONECODE.

    Show progress in downloading a file from web (CSWebDownloader)

    http://code.msdn.microsoft.com/CSWebDownloader-1921136a

      Certainly, the code sample has vb version that you can find it from Gallery or Codeplex.

    Sincerely,

    Jason Wang


    orichisonic http://blog.csdn.net/orichisonic If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    2012年2月8日 8:16
  • Hi ZengWei,

    you can check the URI of the webbrowser before navigating; if it is a file path, you can use webclient or other classes to save the file to the place you want automatically.

    The above operation should be handled in the events of WebBrowser instance.


    Raymond Tang (Microsoft C# MVP)
    Denn Ich Gehoer nur mir
    微软中文论坛同城社区成都QQ群:74268428
    My Blog http://kosmisch.net
    Chengdu,China

    2012年2月8日 11:58
    版主
  • Hi Raymond,

    Yes. The URI is the file path. But I use the codes below can not fetch the file down.

    public void DownFile(string URL, string Filename) { WebClient client = new WebClient(); client.Credentials = new NetworkCredential("logName", "logPwd"); try { WebRequest request = WebRequest.Create(new Uri(URL)); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } try { client.DownloadFile(new Uri(URL), Filename); } catch (WebException e) { Console.WriteLine(e.ToString()); } }

    The reason may be that the web is encrypted by SSL/HTTPS. I am not sure. However I can use the "logname" and "logpwd" to log in the web successfully, and failed to download the files with "WebClient". And, I found I use "WebBrowser.Navigate(FileUri)" to save the file smoothly.

    So do you have any more idea?

    Thanks!

    ZengWei

    2012年2月9日 3:01