Load .htm file in code behind and place the contents in a textbox

I don't think my code is right because I'm loading .txt file I think.

I basically want to load the file Terms.htm and place the contents in tTerms.Text. Thanks.
Dim TermsFile As String = Server.MapPath(Terms.htm")
     Dim objStreamReader As StreamReader 'Create a streamreader class
 
     'open the file
     objStreamReader = File.OpenText(TermsFile)
     Try
       Dim strContents As String = objStreamReader.ReadToEnd()
       objStreamReader.Close()
       tTerms.Text = strContents
      Catch exc As Exception
       tTerms.Text = "Error!!!"
      End Try

Open in new window

wilcor14Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
carmodykConnect With a Mentor Commented:
Try this example:

Public Shared Sub Main()
        Dim path As String = "c:\temp\MyTest.txt"

        Try
           
                  Dim sr As StreamReader = New StreamReader(path)

            'This allows you to do one Read operation.
            Dim strContents As String = sr.ReadToEnd()
       sr.Close()
       tTerms.Text = strContents

                Catch e As Exception
            msgbox(e.Message)
        End Try
    End Sub
0
 
StanicDejanCommented:
I'm guessing you want to take an existing HTML file, then /remove/ all the HTML tags.
In that case, this funtion might be handy...

Public Function StripTags(ByVal HTML As String) As String
    ' Removes tags from passed HTML
    Dim objRegEx As _
        System.Text.RegularExpressions.Regex
    Return objRegEx.Replace(HTML, "<[^>]*>", "")
End Function

HTH,
Dejan
0
All Courses

From novice to tech pro — start learning today.