Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to Intercept WebBrowser Control default download with my custom downloader?

How to Intercept WebBrowser Control default download with my custom downloader?

Scheduled Pinned Locked Moved C#
helpcsharphardwaretutorialquestion
6 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anindya Chatterjee
    wrote on last edited by
    #1

    I have written a C# app, where I used WebBrowser control to visit any webpage. If there is a download in this page, and I want to download it IE7 default download manager pops up and starts download. But I want to use custom download manager (viz. one embedded with my app) to download file from webbrowser control. How to solve the problem? Please help me. I am stuck there..... Thank you in advance.

    Anindya Chatterjee

    A 1 Reply Last reply
    0
    • A Anindya Chatterjee

      I have written a C# app, where I used WebBrowser control to visit any webpage. If there is a download in this page, and I want to download it IE7 default download manager pops up and starts download. But I want to use custom download manager (viz. one embedded with my app) to download file from webbrowser control. How to solve the problem? Please help me. I am stuck there..... Thank you in advance.

      Anindya Chatterjee

      A Offline
      A Offline
      Anthony Mushrow
      wrote on last edited by
      #2

      Right then. WebBrowser has an event for Navigating, which gets called just before the control starts redirects to the new url. You'll need to use the event, and check the extension of the file being downloaded. If the extension is any kind of webpage (htm, html, asp, etc) then you can just ignore it. If the extension is something else (rar, mp3, doc, etc) then you will need to cancel the event, and start your custome downloading code on the url. A quick example:

      void WebBrowser1Navigating(object sender, WebBrowserNavigatingEventArgs e)
      {
      //check for webpages
      if(e.Url.AbsoluteUri.EndsWith(".html"))
      {
      //leave now before we start downloading with custom code
      return;
      }

      //Cancel the event, so the control doesn't start downloading the file itself
      e.Cancel;
      
      //pass e.Url to wherever it needs to go to start downloading
      

      }

      My current favourite word is: Bacon!

      -SK Genius

      S A 2 Replies Last reply
      0
      • A Anthony Mushrow

        Right then. WebBrowser has an event for Navigating, which gets called just before the control starts redirects to the new url. You'll need to use the event, and check the extension of the file being downloaded. If the extension is any kind of webpage (htm, html, asp, etc) then you can just ignore it. If the extension is something else (rar, mp3, doc, etc) then you will need to cancel the event, and start your custome downloading code on the url. A quick example:

        void WebBrowser1Navigating(object sender, WebBrowserNavigatingEventArgs e)
        {
        //check for webpages
        if(e.Url.AbsoluteUri.EndsWith(".html"))
        {
        //leave now before we start downloading with custom code
        return;
        }

        //Cancel the event, so the control doesn't start downloading the file itself
        e.Cancel;
        
        //pass e.Url to wherever it needs to go to start downloading
        

        }

        My current favourite word is: Bacon!

        -SK Genius

        S Offline
        S Offline
        Spacix One
        wrote on last edited by
        #3

        what if it goes to an ASP, PHP, ASPX, DHTML, SHTML, JSP, ect.. page?!?! You "could" create a web client object that spits it's request into the webbrowser control to be displated. Then you have access to the HTTP headers! but, then you can't port it over to the compact framework without lots of work openNETCF library only to find a bug in openNETCF and have your project grind to a halt to be canceled :(


        -Spacix All your skynet questions[^] belong to solved

        A 1 Reply Last reply
        0
        • A Anthony Mushrow

          Right then. WebBrowser has an event for Navigating, which gets called just before the control starts redirects to the new url. You'll need to use the event, and check the extension of the file being downloaded. If the extension is any kind of webpage (htm, html, asp, etc) then you can just ignore it. If the extension is something else (rar, mp3, doc, etc) then you will need to cancel the event, and start your custome downloading code on the url. A quick example:

          void WebBrowser1Navigating(object sender, WebBrowserNavigatingEventArgs e)
          {
          //check for webpages
          if(e.Url.AbsoluteUri.EndsWith(".html"))
          {
          //leave now before we start downloading with custom code
          return;
          }

          //Cancel the event, so the control doesn't start downloading the file itself
          e.Cancel;
          
          //pass e.Url to wherever it needs to go to start downloading
          

          }

          My current favourite word is: Bacon!

          -SK Genius

          A Offline
          A Offline
          Anindya Chatterjee
          wrote on last edited by
          #4

          Thanks, very much. My problem has been solved by your solutions. Thanks again.

          Anindya Chatterjee

          1 Reply Last reply
          0
          • S Spacix One

            what if it goes to an ASP, PHP, ASPX, DHTML, SHTML, JSP, ect.. page?!?! You "could" create a web client object that spits it's request into the webbrowser control to be displated. Then you have access to the HTTP headers! but, then you can't port it over to the compact framework without lots of work openNETCF library only to find a bug in openNETCF and have your project grind to a halt to be canceled :(


            -Spacix All your skynet questions[^] belong to solved

            A Offline
            A Offline
            Anthony Mushrow
            wrote on last edited by
            #5

            You mean if you go to an asp page and then it automatically downloads a file? Because i think that would trigger the Navigating event as well. If you mean i only put in an if statement for html, then it was just an example of how you could solve the problem.

            My current favourite word is: Bacon!

            -SK Genius

            S 1 Reply Last reply
            0
            • A Anthony Mushrow

              You mean if you go to an asp page and then it automatically downloads a file? Because i think that would trigger the Navigating event as well. If you mean i only put in an if statement for html, then it was just an example of how you could solve the problem.

              My current favourite word is: Bacon!

              -SK Genius

              S Offline
              S Offline
              Spacix One
              wrote on last edited by
              #6

              The problem with that is you can't account for every type of viewable file on the web :( ranting about how you can't grab the HTTP headers from the web browser control, as I've been in a similar issue trying to "capture" POST data from the web browser... X|


              -Spacix All your skynet questions[^] belong to solved


              I dislike the black-and-white voting system on questions/answers. X|


              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups