WebBrowser Object - Respond to File Download/Save As Windows
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: WebBrowser Object - Respond to File Download/Save As Windows

  1. #1
    Join Date
    Dec 2009
    Posts
    4

    WebBrowser Object - Respond to File Download/Save As Windows

    Hello everyone,

    I am writting a Windows Form application (C# .NET 2.0 using VS 2008) that uses a WebBrowser object to navigate to various web pages, to do some automation for certain tasks. One of the tasks I need to do is to download files, where I click on a link and save a report to my hard drive (or a folder on the network).

    I can programically click the link to start the download, but I have no idea how to repond to the 'File Download' and 'Save As' windows, to actually download the file.

    Any ideas or suggestions would really be appreciated. Let me know if you have any questions.

    Thanks!

  2. #2
    Join Date
    Sep 2006
    Posts
    31

    Re: WebBrowser Object - Respond to File Download/Save As Windows

    Instead of clicking the link try to extract the link and call this methode..
    Code:
    public void DownloadFile(String sFileUrl, String destination, String sFileName)
            {
                System.Net.WebClient wc = new System.Net.WebClient();
                try
                {
    
                    wc.DownloadFile(sFileUrl, destination + "\\" + sFileName);
                    MessageBox.Show("Download succesvol");
                }
                catch
                {
                    MessageBox.Show("Unable to download file " + sFileUrl );
                }
            }

  3. #3
    Join Date
    Dec 2009
    Posts
    4

    Re: WebBrowser Object - Respond to File Download/Save As Windows

    Thanks for the reply kristof1104.

    I took another look at the webpage that has the link to download the report. I just now realised is that the link does not point to a specific filename, but to a javascript function in the page. From what I can tell, the function resumits the same page to itself.

    Anyone have any recommendations on how I might be able to proceed?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center