First of all my application is not a web application. My aim is reading html files and modify them.
So that I write this code:
string fileName =
Get position of start and end index of section_1
stringIndex =StringNthOccFinder.IndexOfNth(HtmlSting, "<Section_1", 0, 1);
endIdex = StringNthOccFinder.IndexOfNth(HtmlSting, "</Section_1>", 0, 14);
get HTML section which you want to remove
HtmlSection= result.Substring(stringIndex , endIdex - stringIndex );
Replace html section to ""
result = result.Replace(HtmlSection, "");
You can load the HTML as XML using XElement etc, but ultimately if you are removing or inserting characters you will need to resize the file and relocate the characters.
Install the HAP package:
Install-Package HtmlAgilityPack -Version 1.11.27
String:
// From String
string result ="<div id="RemoveableDiv"></div> <div id="2"></div>"
Code:
var doc = new HtmlDocument();
doc.LoadHtml(result);
foreach (var node in doc.DocumentNode
.Descendants("div")
.Where(d => d.GetAttributeValue("Id", "RemoveableDiv").IndexOf("NavContent") >= 0)
.ToArray())
node.Remove();
result = doc.documentnode.innerhtml;
If you are wanting to just change certain things, you could be able to do this with XPath. Using the HTML Agility Pack, you can do this using C#.
http://htmlagilitypack.codeplex.com/