Search web site
Search the web site
Original Author: Bhushan-
Code
As the website increases you should provide an option for the user to trace out what he is looking for, in a very short time. For this reason search this website help you a lot.
Open your favorite editor and paste this code their. save the file as textsearch.asp.
Search Results for :- <%=Request("SearchText")%>
<%
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("/news"))
Dim objFile, objTextStream, strFileContents, bolFileFound
bolFileFound = False
dim count
count=0
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
count=count+1
Response.Write "
"
'This program will do the search in the path specified only. if you want it to search through all your 'directories/folders use a different logic. here i have specified the path as /news. change the path accordingly.
Response.Write " www.plnaet-source-code.com" & objFile.Name & "
"
Response.Write ("
")
bolFileFound = True
End If
objTextStream.Close
End If
Next
if Not bolFileFound then
Response.Write "No matches found..."
else
Response.Write "Total no of pages found=" & count & "
"
'Response.Write "click for more information:-.." & "
"
end if
Set objTextStream = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
%>
Next open another page and type in the following code;
Loading Comments ...
Comments
No comments have been added for this post.
You must be logged in to make a comment.