How to Read and Replace this Content

Posted by Jayakumars under .NET Certifications on 1/22/2015 | Points: 10 | Views : 482 | Status : [Member] [MVP] | Replies : 1
Hi
I read html file using streamReader here how to read and replace particular tag

for ex : img src attrribute replace how will do this

This is my html file
<html>
<b>ddd</B>
<img alt="Image" border="0" src="Home.png" width="536" height="72" />
<u>Test<u>
</html>

here how to read and replace src tag Home.png to Test.png how will do this

Mark as Answer if its helpful to you


Responses

Posted by: Gunam on: 2/9/2015 [Member] Starter | Points: 25

Up
0
Down
There is a DLL called HtmlAgility pack from that you can iterate through html nodes in c#.


HtmlDocument doc = new HtmlDocument();
doc.Load("myfile.htm");
foreach(HtmlNode node in doc.DocumentElement.SelectNodes("//img[@src"])
{
HtmlAttribute att = node["src"];
att.Value = "//your new image path";
}
doc.Save("myfile.htm");

Guna

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response