On the Form's class, add this code:
[highlight=vb.net] Private Sub WebBrowser1_Navigating(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs ) Handles WebBrowser1.Navigating
'Credits to lubos hasko and Michael Sun [MSFT] for this code
'I, master131 wrote the comments btw :3
'This code checks whether the object being loaded is just a HTML file (or some other object) or an actual file being downloded
'Please note that this code will only catch file extension types that are recognised by the OS
'Some extensions that are natively supported by the browser such as .txt files are not supported
'If you want to catch specific file types that aren't supported then use this code as an example:
'If e.Url.Segments(e.Url.Segments.Length - 1).EndsWith(".extensionHere") Then
' e.Cancel = true
' 'Blah, use the URL, whatever
'End If
'I recommend you do not use HTML or PHP files with the above code as it can totally fuck up your browser.
'Also take note that the ABOVE code won't be able to catch every file that ends with a specific
'extension as some download links may look like this:
http://www.somesite.com/download/file/fsd352m234ma4
Dim request As System.Net.WebRequest = System.Net.WebRequest.Create(e.Url)
request.Method = "HEAD"
Dim response As System.Net.WebResponse = request.GetResponse()
If response.ContentType = "application/octet-stream" Or response.ContentType.StartsWith("image/") Then
e.Cancel = True
'Do crap with the link here
'Use: e.Url.ToString to obtain the download link
'For example, you could create a form that downloads files. Then just simply pass the link over from here to the other form and profit??
End If
response.Close()
End Sub[/highlight]