writing the contents of a file to a asp:textbox RRS feed

  • Question

  • User683176063 posted

    trying to read a file into a textbox line by line but nothing shows up

    any ideas?

    <%@ Import Namespace="System" %>
    <%@ Import Namespace="System.IO" %>
    <%@ Import Namespace="System.Text" %>

    <%@ Page Language="c#"%>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />


     <div class>

    <form id="form1" runat="server">
    <asp:TextBox runat="server" ID="textbox1" Width="500" Height=500 />

       string line="";
       System.IO.StreamReader file = new System.IO.StreamReader(@" C:\\Inetpub\\wwwroot\test\\parking.csv"); 
        while((line = file.ReadLine()) != null) 
          this.textbox1.Text = line  + Environment.NewLine;




    Friday, August 31, 2018 10:08 PM

All replies

  • User475983607 posted

    Please learn how to use the debugger.  You are overwriting the Text property on ever loop iteration.  The last iteration is probably just a new line.

        while((line = file.ReadLine()) != null)  
          this.textbox1.Text += line  + Environment.NewLine;

    Also, use the browser's developer tools (F12) to view the HTML to make sure the textbox is not showing an empty line.

    Friday, August 31, 2018 11:12 PM