Webbrowser and my download manager

michalss

Member
Joined
Jan 2, 2008
Messages
8
Programming Experience
Beginner
Hi im trying make may own webbrowser where i m using comp. webbrowser. Everything is simple except implementation my own download manager and disable manager from IE. Means when im click on the download button in the webbrowser i want to open my download manager...

P.S This is global problem im looking for sulution about 10 days without success..

Thx for every reply..
 
The managed WebBrowser control can't do this, but extending it with the ActiveX browser I made a few successful interceptions, this was MS downloads where you never see the real file url. You have to add reference to COM library "Microsoft Internet Controls".
VB.NET:
Private WithEvents svd As SHDocVw.WebBrowser

Private Sub frmDiv_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
    svd = Me.WebBrowser1.ActiveXInstance
End Sub

Private Sub svd_NewWindow3(ByRef ppDisp As Object, ByRef Cancel As Boolean, _
ByVal dwFlags As UInteger, ByVal bstrUrlContext As String, ByVal bstrUrl As String) _
Handles svd.NewWindow3
    If bstrUrlContext = svd.LocationURL Then
        Cancel = True
        '[COLOR="Green"]bstrUrl[/COLOR] was the file url in my tests
    End If
End Sub
Use the WB to navigate as normal, Me.WebBrowser1.Navigate("url").
Try it and give feedback, I have't tried more than a few files so there may be bugs in code/logic.
 
Thanks mate
I have try it but i did not work. May i doing smt wrong (im just begginer) but i followed you instuctions. I have to add reference to COM library "Microsoft Internet Controls" and itegarate you code to my project.Not working yeat. Can you give me all you project code you try it on pls?

This is my simple code i have try use it on :
VB.NET:
Public Class Form1
    Dim adresa As String

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        adresa = TextBox1.Text
        If adresa = ("") Then
            MsgBox("Musite zadat adresu")
        Else
            WebBrowser1.Navigate(adresa)
        End If

    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        adresa = TextBox1.Text

    End Sub

    Private WithEvents svd As SHDocVw.WebBrowser

    Private Sub frmDiv_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
        svd = Me.WebBrowser1.ActiveXInstance
    End Sub

    Private Sub svd_NewWindow3(ByRef ppDisp As Object, ByRef Cancel As Boolean, _
    ByVal dwFlags As UInteger, ByVal bstrUrlContext As String, ByVal bstrUrl As String) _
    Handles svd.NewWindow3
        If bstrUrlContext = svd.LocationURL Then
            Cancel = True
            'bstrUrl was the file url in my tests
        End If
    End Sub

End Class

Thx again
 
Looks like you've got it. You have interest in 'bstrUrl' in NewWindow3 event when you click a file download in the webpage.
 
I don't have any more code than that. I don't know what you mean by "not working".
 
I don't have any more code than that. I don't know what you mean by "not working".


Well means when i click on download link still IE download manager show up and my own not and disable IE manager on the first place.My original post was how to downlaod files by my own manager.

Thank you very much for yr help and if you have some different solution then post it in here pls.

Thx again
 
Ok, "link" now, it worked for download buttons that "pops" the file. I found the file url for anchor links like code below, however the Cancel parameter doesn't work in the AX FileDownload event. The managed WebBrowser control is missing the cancel option also.
VB.NET:
Private Sub svd_FileDownload(ByVal ActiveDocument As Boolean, ByRef Cancel As Boolean) Handles svd.FileDownload
    Dim x As HtmlElement = Me.WebBrowser1.Document.ActiveElement
    If x IsNot Nothing Then
        Cancel = True
        Dim fileUrl As String = x.GetAttribute("href")
    End If
End Sub
Here's another idea that seems to work in some cases..
VB.NET:
Private isFileDownload As Boolean

Private Sub WebBrowser1_FileDownload(ByVal sender As Object, ByVal e As System.EventArgs) Handles WebBrowser1.FileDownload
    isFileDownload = True
End Sub

Private Sub WebBrowser1_Navigating(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) _
Handles WebBrowser1.Navigating
    If Me.isFileDownload AndAlso e.TargetFrameName = String.Empty Then
        e.Cancel = True
        Dim fileurl As String = e.Url.ToString
    End If
    Me.isFileDownload = False
End Sub
The problems with this approach is you can't just download the file url independently if it was fetched when user is logged in to private network, you'll just get the standard login page in return. Also the filename may be concealed so you wouldn't know which file it is, just look at the urls for post attachments at this site; they are merely id numbers to a php script link. I think the only way to do this properly is to implement the IDownloadManager interface with a COM object, which would have system wide impact.
 
Back
Top