Click here to Skip to main content
15,895,848 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
It is possible to load a html page(online one) in webBrowser BUT, Before loading it into webBrowser, to load it into a string, clean some tags there, and Then loading that string into webBrowser ?
Or any other variant?
I want to load certain tags from a web page into my webBrowser, and NOT the whole original page.(for example only a list, or only the images- from a specific page)
Can be done?
I suppose it must be done with the help of php, but i dont know it.
Thanks, once again.

For example:
If I have to load this page: http://translate.google.co.uk/?hl=en&tab=TT
I want to be able to get rid of the " <<pre>div id="gb">" INSIDE that page. (That div is the top menu from that page).
Posted
Updated 26-Nov-11 15:08pm
v8

You may do this in two steps.

1) Read content from HTML file. -

Either you can read content of your HTML file using WebClient().
C#
client = new WebClient();
String htmlString = client.DownloadString("MyFile.htm");


Or using StreamReader.
C#
String htmlString = String.Emtpy;
using( StreamReader reader = new StreamReader( @"MyHtmlFilePath" ) )
{
   htmlString = reader.ReadToEnd(); 
}


2) Then modify your htmlString and assign it to WebBrowser Control using DocumentText Property. Have a look at below link for more information on this.

http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.documenttext.aspx

I also found below link interesting.

http://geekswithblogs.net/dotnetnomad/archive/2008/01/29/119065.aspx

Update - Since you updated your Question.
Quote:
I suppose it must be done with the help of php, but i dont know it.

Why you need PHP for this? You can modify/manupulate your HTML sting using simple StringBuilder or using "Html Agility Pack".

http://htmlagilitypack.codeplex.com/
 
Share this answer
 
v2
Comments
_Q12_ 26-Nov-11 11:20am    
see the example I updated the page.
RaisKazi 26-Nov-11 11:26am    
Ok so whats the problem. You may exclude it from your HTML string using "Html Agility Pack" or "Regular Expression".
http://www.codeproject.com/KB/dotnet/regextutorial.aspx

http://www.codeproject.com/KB/aspnet/regex1.aspx
_Q12_ 26-Nov-11 11:40am    
OK, I'll look over the "Html Agility Pack", But I never worked with it... I hope is free and not too complicated, and most of all to do what i need to do...
If I encounter problems, can I discuss them further with you here?
I then give you a big +5 stars if anything looks good. ;)
RaisKazi 26-Nov-11 12:10pm    
Sure. But I would have gone with "Regular Expressions" for this as a deal is to only exclude one div tag. I may not be available too long as its my Bed-Time :). But you may post your difficulties as a separate Question and I am sure some one will provide you solution. Will wait for that big +5 stars :).
_Q12_ 26-Nov-11 12:38pm    
Im not so advanced in programming ... so I think I cant load a web page in my webBrowser after all with this class... I managed to reference its dll, I write the first class from it:
HtmlAgilityPack.HtmlDocument hhh = new HtmlAgilityPack.HtmlDocument();
hhh.Load(html);
But its awfully complicated and way over my head.
So I must stick with using System resources for now...
Thanks for your support anyway.
Have you tried setting the DocumentText property?

WebBrowser1.DocumentText = "<html><head><title>Hi</title></head><body>Hello world!</body></html>";
 
Share this answer
 
Comments
_Q12_ 26-Nov-11 11:01am    
Please read the content of the question first.
Yvan Rodrigues 26-Nov-11 11:35am    
I did but you didn't say which part your having difficulty with. If the document that you are retrieving is valid XML you can load it into an XDocument or XmlDocument object and manipulate it there. Otherwise you're stuck manipulating it with regular expressions.
Sergey Alexandrovich Kryukov 26-Nov-11 21:14pm    
Basically, you are right. This solution misses the first step (see the solution by Rais), but I also had an impression that OP had a problem with loading a document as HTML string. I voted 4.
--SA
You can load any HTML Page into the Your WebBrowser through code :
C#
System.Uri PagePath;
System.Uri.TryCreate("HTML File Path", UriKind.RelativeOrAbsolute,out PagePath);
WebBrowser1.Url = PagePath;
 
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