How to create a simple search engine
S T E P - 1
- We need a search form in HTML format:
S T E P - 2
- We can create a ASP page to show the search result.
- First, we create a FileSystemObject, and use it to get all files in the current folder:
<%
Dim fSys, objFolder, objTxtStream
Dim blnFileFound
blnFileFound = "false"
Set fSys = CreateObject("Scripting.FileSystemObject")
Set objFolder = fSys.GetFolder(Server.MapPath(".")) < color="red" size="+1">'Get the current folder object
%>
S T E P - 3
- Use the objFolder object to get all files in the current folder:
<%
For Each objFile in objFolder.Files
Set objTxtStream = fSys.OpenTextFile(objFile.Path,1)
If Not objTxtStream.AtEndOfStream then < color="red" size="+1">'If Not empty file
strFileContents = objTxtStream.ReadAll
objTxtStream.Close
If InStr(1, strFileContents, Request.form(("SearchKey")), 1) Then
Response.Write "Current folder/" & file_path & _
blnFileFound = "True"
End If
End If
Next
If blnFileFound = "false" Then
Response.write "File Not found give a different search criteria"
End If
Set objFolder = Nothing
Set fSys = Nothing
%>
This is the search result:
No comments:
Post a Comment