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

How will you display .txt file’s text in multi line textbox through ASP.NET 2.0?
  • 1939
Download Files:
 

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

 

 

  t1.JPG

 

Figure 1: Add Existing Item in Solution Explorer.

 

Step 4: Then add any .txt file.

 

 

  t2.JPG

 

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:

 

 

  t3.JPG

 

Figure 3: .txt file in multi line textbox.

Categories

More Articles

© 2013 dotNetheaven. All rights reserved.