Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI
I have a code that i found on the internet. it is made for vb 2003:
Apparently it disables the pictures on a page, which sounds fair after looking to the code. But as i said, its made for vb 2003 and i can't get it to work in vb.net.

Dim origHTML As String
origHTML = WebBrowser1.DocumentText
Dim newHTML As String
Dim regex As String = "<img.*/>"
newHTML = regex.Replace(origHTML, regex, "", regex.Multiline)
WebBrowser1.DocumentText = newHTML


Thanks for help.
Posted
Updated 6-Nov-10 22:10pm
v2
Comments
DaveAuld 7-Nov-10 5:04am    
VB 2003 used an early version of .Net, so providing you have type the code correctly it should work, do you get any build errors or exceptions thrown, how does it not work? does it still show the images? your regex doesn't cater for any white space between the opening tag symbol and 'img' as well.
euhiemf 7-Nov-10 5:16am    
It doesn't disable the pictures and the "regex.Multiline" doesn't work either...
Because the regex.Multiline doesn't work i thought of just doing this:

newHTML = regex.Remove(regex)

but it doesn't work either.
Thanks for helping me.
(was my English crapy there?)

I had a look at the code, and you have not declared the RegExg object.

You need an import statement, and also a RegEx object; see the code below;

VB
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub ButtonGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonGo.Click
        'Navigate to Address
        WebBrowser1.Navigate(TextBoxAddress.Text)
End Sub
Private Sub ButtonKillImages_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonKillImages.Click
    'Source String
    Dim origHTML As String
    origHTML = WebBrowser1.DocumentText
    'New String for Ouput
    Dim newHTML As String
    'The Regular Expression Object
    Dim regx As New Regex("<img.*/>")
    'Perform the RegEx action
    newHTML = regx.Replace(origHTML, "")
    'Load back into browser the new string
    WebBrowser1.DocumentText = newHTML
End Sub
End Class
 
Share this answer
 
Comments
euhiemf 7-Nov-10 5:35am    
Thank you so much!
Great!
But it is alredy loaded!
Just disabled displaying not loading!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900