Results 1 to 4 of 4

Thread: [RESOLVED] StreamReader and TextBox Not Displaying Data Correctly

  1. #1

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,828

    Resolved [RESOLVED] StreamReader and TextBox Not Displaying Data Correctly

    I need to read a file on a server into a textbox. I did a test on my local PC, to make sure it works the same in a web app as it does on a desktop app.

    The data appears to read just fine, but it doesn't display properly. The test file in the screenshot below, shows how the data should be displayed. When using a desktop app, the data displays just like this.



    But on the web app, I get this:



    Although the TextBox appears to be MultiLine, it only displays the data in the middle of the box and as one line. Am I missing something?
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  2. #2
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: StreamReader and TextBox Not Displaying Data Correctly

    Hello,

    Can you show the code that you are using?

    I have just tried this:

    Code:
            protected void Page_Load(object sender, EventArgs e)
            {
                string fileText = File.ReadAllText(Server.MapPath("TextFile1.txt"));
                this.TextBox1.Text = fileText;
            }
    With this:

    Code:
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Rows=20 />
        </div>
        </form>
    </body>
    </html>
    And it worked exactly as expected.

    The problem that you could be facing is with the rendering of the Environment.NewLine to br tags in the textbox.

    Gary

  3. #3

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,828

    Re: StreamReader and TextBox Not Displaying Data Correctly

    Oops. I never actually set the Multiline property in the source code. I just assumed that since it looked multilined that it would be, like in a desktop app. I know there's still a property in desktop apps, but I couldn't locate it in the properties window and when I Googled it earlier, every post I saw talked about using these elaborate Javascript options to force it.

    Thanks
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  4. #4
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [RESOLVED] StreamReader and TextBox Not Displaying Data Correctly

    Not a problem at all.

    Happy to help!

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width