none
WebBrowser - How to intercept download RRS feed

  • Question

  • In a WPF application I have a WebBrowser control that opens a site for a printer configuration. The printer gets configured and at the end a button is pressed to download the results as a spreadsheet. The creation of the spreadsheet is done by a javascript function.

    If the window is opened in a normal browser the file is automatically downloaded and saved.

    How can I intercept the file via the WebBrowser and save it to a string?


    Monday, May 28, 2018 9:11 AM

All replies

  • Hi pmariotti,

    You said if the window is opened in a normal browser the file is automatically downloaded and save, can you tell  if the saved content comes from webbrowser? If yes, you can read webbrowser content and save it to string. If no, you need to download the file and read this file from your computer, save it to string.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, May 29, 2018 7:04 AM
    Moderator
  • No, perhaps I have not explained correctly.

    The link is to an HP A3 printer configuration site. If I open the site with any browser I can configure a printer and then click on a button that causes a click to go to a Javascript function that builds the Excel spreadsheet and sends it to the browser's download manager, which sends it back to my IE or Chrome chosen download folder.

    If I open the link in a .Net WebBrowser control (which does not have its own download manager) the link opens correctly, configures correctly and when the download button is clicked may (i do not know since I have no way of checking) actually send a response somewhere.

    I need to intercept that response and save the downloaded spreadsheet. If I were to do this in Winforms, the WebBrowser control has its own download manager and c# code can interact with it.

    Unfortunately the application of the WebBrowser is a .Net web site, and the .Net WebBrowser has no download manager, it just calls some version of IE through interop.

    I am told by some comments in various search results that I will need to write my own download manager and add it to the WebBrowser services, but I have no clue of how one does this.

    Any ideas?

     

    Tuesday, May 29, 2018 8:14 AM
  • I only use Chrome but here is something to think about.  You know the download folder so when you click the button start a FIleSystemWatcher instance and then wait until that instance indicates a change in the folder.  While not elegant it is most likely less work than trying to implement a download manager.

    https://docs.microsoft.com/en-ca/dotnet/api/system.io.filesystemwatcher?view=netframework-4.7.1


    Lloyd Sheen


    • Edited by sqlguy Tuesday, May 29, 2018 8:18 PM
    Tuesday, May 29, 2018 8:17 PM
  • Thank you for the suggestion, but it will not work.

    I may have several people sing the site at the same time, and more than one file appearing in the IE download folder. Could not tell which is which...

    Wednesday, May 30, 2018 6:33 AM