<%@ Import Namespace="System.IO"%> <%@ Page Language="C#" Debug="true" %> <script runat="server"> void Page_Load(object sender, EventArgs e) { StreamReader StrWer; StringBuilder StrBui; string strLine = null; string SearchText = "2008"; int intLine = 0; string strNum = null; StrWer = File.OpenText(Server.MapPath("MyFiles/") + "thaicreate.txt"); StrBui = new StringBuilder(); while (!(StrWer.EndOfStream)) { intLine = intLine + 1; strLine = StrWer.ReadLine(); if(strLine.IndexOf(SearchText) > -1) { strLine = strLine.Replace(SearchText, "<span style=\"background-color:red;\">" + SearchText + "</span>"); strNum = strNum + intLine + ","; } StrBui.AppendLine(strLine + "<br>"); } this.lblText1.Text = StrBui.ToString(); this.lblText2.Text = "Found Line : " + strNum.ToString(); StrBui = null; StrWer.Close(); } </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>
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท