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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

carmodykCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.