How to Intercept WebBrowser Control default download with my custom downloader?
-
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
-
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
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
-
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
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
-
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
Thanks, very much. My problem has been solved by your solutions. Thanks again.
Anindya Chatterjee
-
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
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
-
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
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|