Copy HTM file contents to InnerHtml

  • Thread starter Thread starter AAaron123
  • Start date Start date
A

AAaron123

In the aspx:
<%@ MasterType VirtualPath="~/Main.master" %>
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="RightCPH">
<div runat="server" style="overflow: auto;" id="History_Parish">
This text gets replaced</div>
</asp:Content>

The reason for the text "This text gets replaced" is that I copy new text to
InnerHtml

In the code behind:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Master.CopyToControlInnerHtml("History\Parish.htm", History_Parish)
End Sub

In the master:
Public Sub CopyToControlInnerHtml(ByVal filename As String,
ByVal ctl As HtmlGenericControl)

Dim fileNameIn As String = Session("TopDirectory") & filename
Dim sr As System.IO.StreamReader
Dim strContents As String = ""
If System.IO.File.Exists(fileNameIn) Then
sr = System.IO.File.OpenText(fileNameIn)
strContents += sr.ReadToEnd()
sr.Close()
Dim pos1 As Integer = strContents.IndexOf("<body")
Dim bodyText As String = strContents.Substring(pos1)
Dim pos2 As Integer = bodyText.IndexOf(">") 'Find end of <body ...>

Dim bodyText2 As String = bodyText.Substring(pos2 + 1).
Replace("</body>", "").Replace("</html>", "")

ctl.InnerHtml = bodyText2
End If
End Sub

As you see I copy the text inside the body elements to InnerHtml.
Seems kind of kludgy to me.
Is there a better way?


Thanks in advance

BTW
Do most Asp.Net developers use .HTM or .HTML??
 
Actually I do use iframe in other places where I want the file's content to
display as it is.
I should have mentioned that I allow the user to choose the effective
stylesheet and I want it to effect the text from the files I copy.
That is, if the user selects a black background style (effects text color,
etc) I want that to be the style for the file's contents copied to
InnerHtml.

Thanks
 
Back
Top