D
Dougsd1r
I have uploaded a text file to my website and can be accessed using a
browser i.e.
http://www.mysite.com/schedule.txt
The text file is just plain text on multiple lines ie
This is a test on line 1
--------------------------------
This is a test on line 3
++++++++++++++++
Line 5
What im trying to achieve is to have a button on my vb form brings up
a msgbox which in turn displays the contexts of the text file
(including the same formatting ie with carriage returns)
I've found sample code on the web which outputs a file to a text box
which i tried to amend but i found that I lost the carriage returns
or line breaks as these were replaced with spaces.
Can any one help me to change this code or is there another way to go
about it
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.TextBox1.Multiline = True
Me.TextBox1.ScrollBars = ScrollBars.Both
'above only for showing the sample
Dim Doc As mshtml.IHTMLDocument2
Doc = New mshtml.HTMLDocumentClass
Dim wbReq As Net.HttpWebRequest = _
DirectCast(Net.WebRequest.Create("http://
msdn.microsoft.com/"), _
Net.HttpWebRequest)
Dim wbResp As Net.HttpWebResponse = _
DirectCast(wbReq.GetResponse(), Net.HttpWebResponse)
Dim wbHCol As Net.WebHeaderCollection = wbResp.Headers
Dim myStream As IO.Stream = wbResp.GetResponseStream()
Dim myreader As New IO.StreamReader(myStream)
Doc.write(myreader.ReadToEnd())
Doc.close()
wbResp.Close()
'the part below is not completly done for all tags.
'it can (will) be necessary to tailor that to your needs.
Dim sb As New System.Text.StringBuilder
For i As Integer = 0 To Doc.all.length - 1
Dim hElm As mshtml.IHTMLElement = _
DirectCast(Doc.all.item(i), mshtml.IHTMLElement)
Select Case hElm.tagName.ToLower
Case "body", "html", "head", "form"
Case Else
If hElm.innerText <> "" Then
sb.Append(hElm.innerText & vbCrLf)
End If
End Select
Next
TextBox1.Text = sb.ToString
End Sub
End Class
I should add that i am using Visual Basic 2005 Express Edition
browser i.e.
http://www.mysite.com/schedule.txt
The text file is just plain text on multiple lines ie
This is a test on line 1
--------------------------------
This is a test on line 3
++++++++++++++++
Line 5
What im trying to achieve is to have a button on my vb form brings up
a msgbox which in turn displays the contexts of the text file
(including the same formatting ie with carriage returns)
I've found sample code on the web which outputs a file to a text box
which i tried to amend but i found that I lost the carriage returns
or line breaks as these were replaced with spaces.
Can any one help me to change this code or is there another way to go
about it
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.TextBox1.Multiline = True
Me.TextBox1.ScrollBars = ScrollBars.Both
'above only for showing the sample
Dim Doc As mshtml.IHTMLDocument2
Doc = New mshtml.HTMLDocumentClass
Dim wbReq As Net.HttpWebRequest = _
DirectCast(Net.WebRequest.Create("http://
msdn.microsoft.com/"), _
Net.HttpWebRequest)
Dim wbResp As Net.HttpWebResponse = _
DirectCast(wbReq.GetResponse(), Net.HttpWebResponse)
Dim wbHCol As Net.WebHeaderCollection = wbResp.Headers
Dim myStream As IO.Stream = wbResp.GetResponseStream()
Dim myreader As New IO.StreamReader(myStream)
Doc.write(myreader.ReadToEnd())
Doc.close()
wbResp.Close()
'the part below is not completly done for all tags.
'it can (will) be necessary to tailor that to your needs.
Dim sb As New System.Text.StringBuilder
For i As Integer = 0 To Doc.all.length - 1
Dim hElm As mshtml.IHTMLElement = _
DirectCast(Doc.all.item(i), mshtml.IHTMLElement)
Select Case hElm.tagName.ToLower
Case "body", "html", "head", "form"
Case Else
If hElm.innerText <> "" Then
sb.Append(hElm.innerText & vbCrLf)
End If
End Select
Next
TextBox1.Text = sb.ToString
End Sub
End Class
I should add that i am using Visual Basic 2005 Express Edition