Question VS 2010 WebBrowserControl Prevent File Downloads

aaronmchale

New member
Joined
Dec 12, 2011
Messages
4
Programming Experience
3-5
I found this code that is supposed to prevent the user from downloading files:

    Private Sub WebBrowser_Navigating(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs)
        Dim HTTPRequest As System.Net.WebRequest = System.Net.WebRequest.Create(e.Url.ToString)
        Dim HTTPResponse As System.Net.WebResponse
        HTTPRequest.Method = "HEAD"
        HTTPResponse = HTTPRequest.GetResponse()
        If (Not HTTPResponse.ContentType.StartsWith("text/")) Then
            e.Cancel = True
            MsgBox("You are not allowed to download files.", MsgBoxStyle.Information, "Download file")
        End If
    End Sub


When the code is run the application stops responding, the problem seems to be the code after the "=" on the second line.

Help please!

Thanks
Aaron
 
Top Bottom