2
Contributors
4
Replies
22
Views
4 Years
Discussion Span
Last Post by Hazuan Nazri
1

Try using the File.ReadAllText() method. It opens a text file, reads all of the lines, then closes the file. You can simply store the results in a string and display the results in a multiline textbox.

Example..

ASPX

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html>
<head runat="server">
    <title>Demo</title>
</head>

<body>
    <form id="form1" runat="server">
        <div>
            <asp:button id="btn1" runat="server" text="Read" onclick="btn_Click" /><br /><br />
            Results:<br />
            <asp:TextBox ID="txtBox1" runat="server" TextMode="MultiLine" Height="250px"></asp:TextBox>
        </div>
    </form>
</body>
</html>

C#

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

public partial class _Default : System.Web.UI.Page
{

    protected void btn_Click(object sender, EventArgs e)
    {
        string txt = File.ReadAllText(Server.MapPath("~/TextFile.txt"));
        txtBox1.Text = txt;
    }
}

TextFile.txt

Line1
Line2
Line3
Line4
Line5

Results

dea44b8702104a82bb6de94b5912cd36

0

nice!!, but i mean i want to fill textbox1 with line1 and textbox2 with line2....can you help me?

0

Do some research on streamreader and the readline() method.

There are other alternatives.

Are you planning to have a predefined number of lines to read or are you planning to create textboxes dynamically?

Edited by JorgeM

0

i think im planing to create textboxes dynamically, because i dont know how much line in the text.txt...

Edited by Hazuan Nazri: wrong word

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.