G
Guest
In ASP.Net 2.0, I would like to stream text, particularly .txt files, into a
content page. I've tried several methods, and none have been satisfactory.
I can generate the stream pretty well using the following code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim appPath As String =
HttpContext.Current.Request.PhysicalApplicationPath
Dim filename As String = file.txt"
Dim rdr As StreamReader
rdr = File.OpenText(appPath & filename)
Dim line As String
' Read and display the lines from the file until the end
' of the file is reached.
Do
line = rdr.ReadLine()
Response.Write(line & "<br>")
Loop Until line Is Nothing
rdr.Close()
End Sub
The problem comes in getting the stream into a contentplaceholder. I can't
find a way to put it there directly. Putting the stream into a label produces
one long string, losing all the paragraphs. Putting it into a textbox formats
the text correctly, but I don't know of any way to have the height of the
textbox expand to fit the text. I tried putting the stream into a user
control, which formats beautifully, and putting that control into the
contentplaceholder, but the user control content loads ahead of the
masterpage content, which all ends up at the bottom of the page.
Is there something i'm missing, or is what I want to do simply not possible?
Thanks in advance for any help.
content page. I've tried several methods, and none have been satisfactory.
I can generate the stream pretty well using the following code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim appPath As String =
HttpContext.Current.Request.PhysicalApplicationPath
Dim filename As String = file.txt"
Dim rdr As StreamReader
rdr = File.OpenText(appPath & filename)
Dim line As String
' Read and display the lines from the file until the end
' of the file is reached.
Do
line = rdr.ReadLine()
Response.Write(line & "<br>")
Loop Until line Is Nothing
rdr.Close()
End Sub
The problem comes in getting the stream into a contentplaceholder. I can't
find a way to put it there directly. Putting the stream into a label produces
one long string, losing all the paragraphs. Putting it into a textbox formats
the text correctly, but I don't know of any way to have the height of the
textbox expand to fit the text. I tried putting the stream into a user
control, which formats beautifully, and putting that control into the
contentplaceholder, but the user control content loads ahead of the
masterpage content, which all ends up at the bottom of the page.
Is there something i'm missing, or is what I want to do simply not possible?
Thanks in advance for any help.