Streaming text to a content page

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.
 
K

Kevin Spencer

Hi Stephen,

Put the text inside a <pre> tag.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Who is Mighty Abbott?
A twin turret scalawag.
 
G

Guest

Thank you for your prompt response.
That got me part way there.
I gave the <pre> tag an ID="readtext".
Using the code I showed before, and making readtext.InnerText = line &
"<br>" resulted in only "<br>" being displayed. Making it readtext.InnerText
= Response.Write(line & "<br>") produced nothing at all.
However, changing it to readtext.InnerText = rdr.ReadToEnd gave me all the
text laid out in paragraphs.
One more thing would make it the way I want: Is there a way to make the text
wrap so the reader doesn't have to scroll to the end of the line? Setting a
width for the <pre> control doesn't seem to do anything.
Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top