Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP Search Engine

Status
Not open for further replies.

Gius

MIS
Sep 20, 2001
12
IT
Hi all,
I had been given this code (search.asp) to search any document in a directory for a specific word. It seems to work fien for ascii files (.txt) and rich text format files (.rtf) but it is not able to read microsoft word 97 document.
Any help would be really appreciated.

Thanks

Code for search.asp:
<HTML>
<HEAD>
<% if Request(&quot;SearchText&quot;) <> &quot;&quot; Then
response.write &quot;<TITLE>Ricerca risultati per &quot;& Request(&quot;SearchText&quot;)& &quot;</TITLE>&quot;
Else
response.write &quot;<TITLE>Pagina Di Ricerca </TITLE>&quot;
End if %>
</HEAD>
<BODY>
<FORM method=&quot;post&quot; action=&quot;search.asp&quot;>
<DIV align=&quot;center&quot;></DIV>
<DIV align=&quot;center&quot;>
<TABLE bgcolor=&quot;#0033CC&quot; border=&quot;0&quot; bordercolorlight=&quot;#00FFFF&quot; bordercolordark=&quot;#000000&quot;>
<TR>
<TD> <FONT color=&quot;#CCCCCC&quot;> <FONT color=&quot;#FFFFFF&quot;>Ricerca</FONT>
<INPUT type=&quot;text&quot; name=&quot;SearchText&quot; size=&quot;40&quot;>
</FONT> </TD>
<TD> <FONT color=&quot;#CCCCCC&quot;>
<INPUT type=&quot;submit&quot; name=&quot;Submit2&quot; value=&quot;Cerca&quot;>
</FONT></TD>
</TR>
<TR>
<TD height=&quot;32&quot;> <FONT color=&quot;#CCCCCC&quot;> <FONT color=&quot;#FFFFFF&quot;>Mostra i risultati</FONT>
<Select name=&quot;rLength&quot; >
<OPTION value=&quot;200&quot; SELECTED>Frase
<OPTION value=&quot;100&quot;>Singola Parola
<OPTION value=&quot;0&quot;>Solo Url
</Select>
<Select name=&quot;rResults&quot;>
<OPTION value=&quot;10&quot; SELECTED>10
<OPTION value=&quot;25&quot;>25
<OPTION value=&quot;50&quot;>50
</Select>
</FONT> </TD>
<TD height=&quot;32&quot;> <FONT color=&quot;#CCCCCC&quot;>
<INPUT type=&quot;reset&quot; name=&quot;Reset&quot; value=&quot;svuota&quot;>
</FONT></TD>
</TR>
</TABLE>
</DIV>
</FORM>
<P><% if Request(&quot;SearchText&quot;) <> &quot;&quot; Then %> </P>
<P><B>Risultati della ricerca per '<%=Request(&quot;SearchText&quot;)%>'</B><BR>
<%
'
' Buscador Simple. Autor Jorge Cisneros
' jorgeci@hotmail.com
'
Const fsoForReading = 1
Dim objFile, objFolder, objSubFolder, objTextStream
Dim bolCase, bolFileFound
Dim strDeTag, Ext, strFile, strContent, strRoot, strTag, strText, strTitle, strTitleL
Dim reqLength, reqNumber, count

strFile = &quot;.txt .rtf .doc&quot;
strRoot = &quot;/&quot;
strText = Request(&quot;SearchText&quot;)
if Request(&quot;Case&quot;) = &quot;on&quot; Then bolCase = 0 Else bolCase = 1
if Request(&quot;rResults&quot;) = &quot;10&quot; Then reqNumber = 10
if Request(&quot;rResults&quot;) = &quot;25&quot; Then reqNumber = 25
if Request(&quot;rResults&quot;) = &quot;50&quot; Then reqNumber = 50
reqLength = Request(&quot;rLength&quot;)
Set objFSO = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set objFolder = objFSO.GetFolder(Server.MapPath(strRoot))

CurURL= &quot; & Request.serverVariables(&quot;SERVER_NAME&quot;)
CurPath = objFolder
schSubFol(objFolder)
For Each objSubFolder In objFolder.SubFolders
schSubFol(objSubFolder)
Next
if Not bolFileFound Then Response.Write &quot;La ricerca non ha trovato nulla..&quot;
if bolFileFound Then Response.Write &quot;<B>Fine Ricerca</B>&quot;
Set objTextStream = Nothing
Set objFolder = Nothing
Set objFSO = Nothing

Sub schSubFol(objFolder)
For Each objFile In objFolder.Files
if Count + 1 > reqNumber or strText = &quot;&quot; Then Exit Sub
if Response.IsClientConnected Then
'Abrir solo si es archivo conocido
strext = right(objFile.Name,3)
if instr(1,strFile,strext) > 0 Then
Set objTextStream = objFSO.OpenTextFile(objFile.Path,fsoForReading)
strContent = objTextStream.ReadAll
if InStr(1,strContent,strtext) > 0 Then
postitle = InStr(1, strContent, &quot;<TITLE>&quot;,1)
if postitle > 0 Then
strTitle = Mid(strContent, postitle + 7, InStr(1, strContent, &quot;</TITLE>&quot;, 1) - (postitle + 7))
Else
strTitle = &quot;File&quot;
End if
Count = Count + 1
Response.Write &quot;<DL><DT><B><I>&quot;& Count &&quot;</I></B> - <A HREF=&quot;&Obt_Url(objFile.path) & &quot;>&quot; & strTitle & &quot;</A></DT><BR><DD>&quot;
strTitleL = InStr(1, strContent, &quot;</TITLE>&quot;, 1) - InStr(1, strContent, &quot;<TITLE>&quot;, 1) + 7
strDeTag = &quot;&quot;
bolTagFound = False
Do While InStr(strContent, &quot;<&quot;)
bolTagFound = True
strDeTag = strDeTag & &quot; &quot; & Left(strContent, InStr(strContent, &quot;<&quot;) - 1)
strContent = MID(strContent, InStr(strContent, &quot;>&quot;) + 1)
Loop
strDeTag = strDeTag & strContent
if Not bolTagFound Then strDeTag = strContent
if reqLength = &quot;0&quot; Then
Response.Write obt_url(objFile.Path) & &quot;</DD></DL>&quot;
Else
Response.Write Mid(strDeTag, strTitleL, reqLength) & &quot;...<BR><I><FONT SIZE='2'>URL: &quot; & obt_url(objFile.Path) & &quot; - Ultima modifica: &quot; & objFile.DateLastModified & &quot; - &quot; & FormatNumber(objFile.Size / 1024) & &quot;Kbytes</FONT></I></DD></DL>&quot;
End if
bolFileFound = True
End if
objTextStream.Close
End if
End if
Next
End Sub
function Obt_Url (nompath)
obt_url = CurUrl +&quot;/&quot;+ right(nompath,len(nompath) - len(curpath)-1)
End function
%>
<% End if %>
</P>
</BODY></HTML>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top