<%@ Import Namespace="System.IO"%>
<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
Dim StrWer As StreamReader
Dim StrBui As StringBuilder
Dim strLine As String
Dim SearchText As String = "2008"
Dim intLine As Integer
Dim strNum As String
StrWer = File.OpenText(Server.MapPath("MyFiles/") & "thaicreate.txt")
StrBui = New StringBuilder()
Do Until StrWer.EndOfStream
intLine = intLine + 1
strLine = StrWer.ReadLine()
If InStr(strLine, SearchText) > 0 Then
strLine = Replace(strLine, SearchText, _
"<span style=""background-color:red;"">" & SearchText & "</span>")
strNum = strNum & intLine & ","
End If
StrBui.AppendLine(strLine & "<br>")
Loop
Me.lblText1.Text = StrBui.ToString()
Me.lblText2.Text = "Found Line : " &strNum.ToString
StrBui = Nothing
StrWer.Close()
End Sub
</script>
<html>
<head>
<title>ThaiCreate.Com ASP.NET - Search Text Files</title>
</head>
<body>
<form runat="server">
<asp:Label id="lblText1" runat="server"></asp:Label><br />
<asp:Label id="lblText2" runat="server"></asp:Label><br />
</form>
</body>
</html>