| | |
|
Active Server Pages help tutorial how to ASP Help ASP Tutorials ASP Programming ASP Code - ASP Free CJWSoft ASPProtect ASPBanner ASPClassifieds
(Advanced)
(Components)
(Database)
(General)
(Vbscript)

|
|
Subject: |
Re: Searching with FileSystemObject |
From: |
Jaspal Khanna |
Date: |
8/2/2000 6:42:29 AM |
IP: |
194.170.163.106 |
Using the FileSystemObject, you can search through all of the files in a particular directory that contain a particular string. To allow for this functionality, you will need two ASP pages: one that presents the user a form to enter the string they wish to search for; the second needs to take this string, iterate through all of the files in a particular folder, and determine which of these files contain the string. Well start by coding the first ASP page, Search.asp, which contains a simple form:
<HTML>
<BODY>
<FORM METHOD=POST ACTION="TextSearch.asp">
Enter text to search for:
<INPUT TYPE=TEXT NAME=SearchText>
<P>
<INPUT TYPE=SUBMIT VALUE="Begin Search!">
</FORM>
</BODY>
</HTML>
TextSearch.asp!
<HTML><BODY>
<B>Search Results for <%=Request("SearchText")%></B><BR>
<%
Const fsoForReading = 1
Dim strSearchText
strSearchText = Request("SearchText")
Now, we want to search all of the files
Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Dim objFolder
Set objFolder = objFSO.GetFolder(Server.MapPath("/"))
Dim objFile, objTextStream, strFileContents, bolFileFound
bolFileFound = False
For Each objFile in objFolder.Files
If Response.IsClientConnected then
Set objTextStream = objFSO.OpenTextFile(objFile.Path,fsoForReading)
strFileContents = objTextStream.ReadAll
If InStr(1,strFileContents,strSearchText,1) then
Response.Write "<LI><A HREF=""/" & objFile.Name & _
""">" & ob |
Previous Message
Follow Up - Re: Searching with FileSystemObject te page is not enough - jaspal khanna 8/2/2000 6:45:48 AM
|
|

|
|
|
|