ASP search for files or folders

Source: Internet
Author: User
Tags html page

This search tool allows you to search for words or phrases on your site, and the resulting page will display the title of your visitors page and a link to it.
You only need to include bellows in the form of your Web page:

HTML page.

<form method= "POST" action= "/cgi-bin/searchfiles.asp" >
<table border=0 cellpadding=5 bgcolor=aaaaaa><tr>
<TD align=center>
Search term or phrase &nbsp; <input type=text name=term size=15> &nbsp; <input type=submit value= "Search" ></td>
</tr></table>
</form>

And you will need to create a file, the content table in the bellow named searchfiles.asp in the corresponding directory. The server that must be available in Active Server Pages. Instructions are at the bottom.

<%
Searchterm = Request.Form ("term")

novalid= "A b c D e F g h i j k l m n o p q R S t u v w x y z Yes No and more"
novalidresponse = "Go back and try again." Your search term is very common "

If InStr (Searchterm,novalid) =0 Then

Response. Write ("<CENTER><H2>Search results</H2></CENTER>")

Foldername= "FolderName"
Showlist ()

Else
Response.Write Novalidresponse
End If

Searchresponse= ""
%>

<%
Sub showlist ()
Foldertocheck = Server.MapPath ("") & "/" & FolderName & "/"
Dim FS, F, F1, FC, S
Set fs = CreateObject ("Scripting.FileSystemObject")
Set f = fs. GetFolder (Foldertocheck)
Set FC = F.files
For each F1 in FC

         wfile = F1.name
           If Right (wfile, 5) = ". html" OR right (wfile, 4) = ". htm" then
       & nbsp;    Wfile2 = foldertocheck & Wfile
             Set fs = CreateObject ("Scripting.FileSystemObject")
             Set a = fs. OpenTextFile (Wfile2)
            ct = a.readall
            A.close
             ct2=lcase (CT)
             SearchTerm2 = LCase (searchterm)

If InStr (Ct2,searchterm2) >0 Then

If InStr (CT, "</title>") >0 Then
LONGITUD=INSTR (CT, "</title>")
Longitud=longitud-1
Ct=left (Ct,longitud)
Longitud2=len (CT)
LONGITUD=INSTR (CT, "<title>")
Longitud=longitud2-longitud-6
Ct=right (Ct,longitud)
Else
If InStr (CT, "</TITLE>") >0 Then
LONGITUD=INSTR (CT, "</TITLE>")
Longitud=longitud-1
Ct=left (Ct,longitud)
Longitud2=len (CT)
LONGITUD=INSTR (CT, "<TITLE>")
Longitud=longitud2-longitud-6
Ct=right (Ct,longitud)
End If
End If

searchresponse= SearchResponse + "<TR><TD>" + ct + "</td><td align=center valign=middle>" + "< A href= "+"/"+ FolderName +"/"+ Wfile +" > more </A></TD></TR>
Longitud=0
Ct= ""

End If
End If

Next

Response.Write ("

Response.Write ("<table border=0 width=550><tr><td bgcolor=c0c0c0><font SIZE=5><B> Search results</b></font></td></tr></table> ")

Response.Write ("<table border=0 width=550>")
If searchresponse<> "" Then
Response.Write SearchResponse
Else
Response.Write ("<tr><td>the specified term or phrase is not found</td></tr>")
End If
Response.Write ("</TABLE>")

Response.Write ("</CENTER></BODY></HTML>")

End Sub
%>

You may contain a variable "novalid" that you do not want to be searched for. If the term is included in the "Novalid" requirement, compose your response variable "novalidresponse".

The text of the search results appears on the search results page above.

"Folder" is the directory search that you want. Only ". Heat medium "and". The HTML "files in this directory will be searched. Subdirectories do not search. If you want to search your top-level directory, set the folder = "". This script is only available in the most useful directory only. I do not recommend checking for more than 50 files (try friendly with your server!). )

This script will display the term phrase required by the page in response to the title list.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.