[RESOLVED] [2005] Html Coding to be displayed in Textbox
Hello sir,
I want HTML coding to be displayed in textbox.
I having 3 forms. When i press button in form2 the code to be executed.
So i used the coding below. But am gettting the path of that html file as output. But i actually wants only the code to be displayed.
Code:
Private Sub LinkLabel4_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel4.LinkClicked
Form3.TextBox.Text = (Application.StartupPath & "\Check\c4.html\")
Form3.Show()
End Sub
Re: [2005] Html Coding to be displayed in Textbox
Thats right - you are setting the textbox's text property to a string which just happens to be the path of a file.
A textbox isn't capable of loading an HTML file directly (or any other file for that matter).
You would need to read the html into a string and then set the text box's text property to that string.
Re: [2005] Html Coding to be displayed in Textbox
Something along the lines of
vb Code:
Imports System.IO
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim line As String
Dim sHTML as String
Dim readFile As System.IO.TextReader = New _
StreamReader((Application.StartupPath & "\Check\c4.html\")
)
While True
line = readFile.ReadLine()
If line Is Nothing Then
Exit While
Else
sHTML = sHTML & line & vbCrLf
End If
End While
readFile.Close()
readFile = Nothing
TextBox.Text = sHTML
Catch ex As IOException
MsgBox(ex.ToString)
End Try
End Sub
End Class
1 Attachment(s)
Re: [2005] Html Coding to be displayed in Textbox
Quote:
Originally Posted by keystone_paul
Something along the lines of
vb Code:
Imports System.IO
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim line As String
Dim sHTML as String
Dim readFile As System.IO.TextReader = New _
StreamReader((Application.StartupPath & "\Check\c4.html\")
)
While True
line = readFile.ReadLine()
If line Is Nothing Then
Exit While
Else
sHTML = sHTML & line & vbCrLf
End If
End While
readFile.Close()
readFile = Nothing
TextBox.Text = sHTML
Catch ex As IOException
MsgBox(ex.ToString)
End Try
End Sub
End Class
I used your coding but i am getting this error during runtime.
Attachment 67809
Re: [2005] Html Coding to be displayed in Textbox
Remove the extra slash at the end of the filename:
Code:
StreamReader((Application.StartupPath & "\Check\c4.html\"))
Code:
StreamReader((Application.StartupPath & "\Check\c4.html"))
Re: [2005] Html Coding to be displayed in Textbox
Sorry I didn't check with your exact filename - as knxrb says just remove the trailing backslash!