ARTICLE

.txt file in multi line textbox in ASP.NET 2.0

Posted by Purushottam Rathore Articles | ASP.NET using VB.NET February 05, 2009
How will you display .txt file’s text in multi line textbox through ASP.NET 2.0?
Download Files:
 
Reader Level:

Steps to display .txt file in multi line textbox:

 

Step 1: Open new website in Microsoft Visual Studio 2005.

 

Step 2: Drop the textbox on the page from the toolbox or you can write the following code.

 

<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" style="overflow.hidden"></asp:TextBox>  

 

Step 3: Go to Solution Explorer and right click on your project. Click on Add Existing Item (See the following figure).

 

 

 

Figure 1: Add Existing Item in Solution Explorer.

 

Step 4: Then add any .txt file.

 

 

 

Figure 2: Add .txt file in your project (here I am adding puru1.txt file).

 

Step 5: Add the System.IO namespace in default.aspx.vb file.

 

Step 6: Write the code on page load (see the given Example).

 

Step 7: Debug your code.

 

For Example:

 

Default.aspx:   

 

<%@ Page Language="VB" AutoEventWireup="true"  CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

    <title>.txt file in multiline textbox</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

    <asp:TextBox ID="TextBox1" runat="server" BorderWidth="2"  Height="50px" Width="200" TextMode="MultiLine" style="overflow.hidden" BackColor="#FFE0C0" ForeColor="Crimson">

    </asp:TextBox>

    </div>

    </form>

</body>

</html>

 

Default.aspx.vb:

 

Imports Microsoft.VisualBasic

Imports System

Imports System.Data

Imports System.Configuration

Imports System.Web

Imports System.Web.Security

Imports System.Web.UI

Imports System.Web.UI.WebControls

Imports System.Web.UI.WebControls.WebParts

Imports System.Web.UI.HtmlControls

Imports System.IO

 

Partial Public Class _Default

          Inherits System.Web.UI.Page

          Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

                   Dim StreamReader1 As New StreamReader(Server.MapPath("puru1.txt"))

                   TextBox1.Text = StreamReader1.ReadToEnd()

                   StreamReader1.Close()

 

          End Sub

End Class

 

Output:

 

 

 

Figure 3: .txt file in multi line textbox.

Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Diagram
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Become a Sponsor