Read a Text file
Partial Class _Default
Inherits
System.Web.UI.Page
Protected Sub Button1_Click(ByVal
sender As Object,
ByVal e As
System.EventArgs) Handles Button1.Click
'to dispaly
content of textfile
Dim fs,
fopen
fs = Server.CreateObject("scripting.filesystemobject")
fopen = fs.opentextfile("c:\a.txt")
Do While Not fopen.atendofstream
Response.Write(fopen.readline &
"<br>")
Loop
End Sub
Protected Sub Button2_Click(ByVal
sender As Object,
ByVal e As
System.EventArgs) Handles Button2.Click
'To display
Characters of text file
Dim fs,
fopen
fs = Server.CreateObject("scripting.filesystemobject")
fopen = fs.opentextfile("c:\a.txt")
Response.Write(fopen.read(2))
End Sub
Protected Sub Button3_Click(ByVal
sender As Object,
ByVal e As
System.EventArgs) Handles Button3.Click
'to dispaly
firstline of textfile
Dim fs,
fopen
fs = Server.CreateObject("scripting.filesystemobject")
fopen = fs.opentextfile("c:\a.txt")
Response.Write(fopen.readline)
End Sub
Protected Sub Button4_Click(ByVal
sender As Object,
ByVal e As
System.EventArgs) Handles Button4.Click
'to dispaly
content of textfile with line no
Dim fs,
fopen
fs = Server.CreateObject("scripting.filesystemobject")
fopen = fs.opentextfile("c:\a.txt")
Do While Not
fopen.atendofstream
Response.Write(fopen.line & " " & fopen.readline)
Loop
End Sub
End Class
<%@ Page Language="VB"
AutoEventWireup="false"
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>Untitled
Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="dispaly content of textfile" />
<asp:Button ID="Button2" runat="server" Text="dispaly character of textfile" />
<asp:Button ID="Button3" runat="server"
Text="Display first line of text file" />
<asp:Button ID="Button4" runat="server"
Text="content of textfile with line no" />
<br />
<br />
</div>
</form>
</body>
</html>
hi I like this blog - omkar
ReplyDelete