Include contents of an html page in an aspx page
The use of System.IO and regular expressions makes this a very easy task. Place a <asp:Literal> control (ID="htmlbody") on your page, and then use the following code to strip out everything up to and including the <body> tag (regardless of whether the tag contains additional attributes), and everything from the closing </body> tag onwards:
StreamReader sr;
string html;
sr = File.OpenText("<path_to_file.htm>");
html = sr.ReadToEnd();
sr.Close();
Regex start = new Regex(@"[\s\S]*<body[^<]*>", RegexOptions.IgnoreCase);
html = start.Replace(html,"");
Regex end = new Regex(@"</body[\s\S]*", RegexOptions.IgnoreCase);
html = end.Replace(html, "");
htmlbody.Text = html;
Currently rated 4.13 by 16 people
Rate Now!
Date Posted:
05 May 2007 20:44
Last Updated:
16 May 2009 17:36
Posted by:
Mikesdotnetting
Total Views to date:
35227



Comments
18 November 2009 07:31 from pranav
what does below code means?
"[\s\S]*<body[^<]*>"
18 November 2009 19:56 from Mikesdotnetting
@pranav
It's part of a regular expression pattern. It attempts to locate the body tag in the html, and allows for cases where there might be inline styling or javascript onload function calls. Or indeed anything else.
23 March 2010 22:37 from Jason
I have a aspx page where I have it inside of a master page. I want to add javascript but I know you can only do this in a html page. I am just wanting to know is ther a way to add javascript to a aspx page.