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("SearchText"
<> "" Then
response.write "<TITLE>Ricerca risultati per "& Request("SearchText"
& "</TITLE>"
Else
response.write "<TITLE>Pagina Di Ricerca </TITLE>"
End if %>
</HEAD>
<BODY>
<FORM method="post" action="search.asp">
<DIV align="center"></DIV>
<DIV align="center">
<TABLE bgcolor="#0033CC" border="0" bordercolorlight="#00FFFF" bordercolordark="#000000">
<TR>
<TD> <FONT color="#CCCCCC"> <FONT color="#FFFFFF">Ricerca</FONT>
<INPUT type="text" name="SearchText" size="40">
</FONT> </TD>
<TD> <FONT color="#CCCCCC">
<INPUT type="submit" name="Submit2" value="Cerca">
</FONT></TD>
</TR>
<TR>
<TD height="32"> <FONT color="#CCCCCC"> <FONT color="#FFFFFF">Mostra i risultati</FONT>
<Select name="rLength" >
<OPTION value="200" SELECTED>Frase
<OPTION value="100">Singola Parola
<OPTION value="0">Solo Url
</Select>
<Select name="rResults">
<OPTION value="10" SELECTED>10
<OPTION value="25">25
<OPTION value="50">50
</Select>
</FONT> </TD>
<TD height="32"> <FONT color="#CCCCCC">
<INPUT type="reset" name="Reset" value="svuota">
</FONT></TD>
</TR>
</TABLE>
</DIV>
</FORM>
<P><% if Request("SearchText"
<> "" Then %> </P>
<P><B>Risultati della ricerca per '<%=Request("SearchText"
%>'</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 = ".txt .rtf .doc"
strRoot = "/"
strText = Request("SearchText"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
if Request("Case"
= "on" Then bolCase = 0 Else bolCase = 1
if Request("rResults"
= "10" Then reqNumber = 10
if Request("rResults"
= "25" Then reqNumber = 25
if Request("rResults"
= "50" Then reqNumber = 50
reqLength = Request("rLength"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
Set objFSO = Server.CreateObject("Scripting.FileSystemObject"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
Set objFolder = objFSO.GetFolder(Server.MapPath(strRoot))
CurURL= " & Request.serverVariables("SERVER_NAME"
CurPath = objFolder
schSubFol(objFolder)
For Each objSubFolder In objFolder.SubFolders
schSubFol(objSubFolder)
Next
if Not bolFileFound Then Response.Write "La ricerca non ha trovato nulla.."
if bolFileFound Then Response.Write "<B>Fine Ricerca</B>"
Set objTextStream = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
Sub schSubFol(objFolder)
For Each objFile In objFolder.Files
if Count + 1 > reqNumber or strText = "" 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, "<TITLE>",1)
if postitle > 0 Then
strTitle = Mid(strContent, postitle + 7, InStr(1, strContent, "</TITLE>", 1) - (postitle + 7))
Else
strTitle = "File"
End if
Count = Count + 1
Response.Write "<DL><DT><B><I>"& Count &"</I></B> - <A HREF="&Obt_Url(objFile.path) & ">" & strTitle & "</A></DT><BR><DD>"
strTitleL = InStr(1, strContent, "</TITLE>", 1) - InStr(1, strContent, "<TITLE>", 1) + 7
strDeTag = ""
bolTagFound = False
Do While InStr(strContent, "<"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
bolTagFound = True
strDeTag = strDeTag & " " & Left(strContent, InStr(strContent, "<"
- 1)
strContent = MID(strContent, InStr(strContent, ">"
+ 1)
Loop
strDeTag = strDeTag & strContent
if Not bolTagFound Then strDeTag = strContent
if reqLength = "0" Then
Response.Write obt_url(objFile.Path) & "</DD></DL>"
Else
Response.Write Mid(strDeTag, strTitleL, reqLength) & "...<BR><I><FONT SIZE='2'>URL: " & obt_url(objFile.Path) & " - Ultima modifica: " & objFile.DateLastModified & " - " & FormatNumber(objFile.Size / 1024) & "Kbytes</FONT></I></DD></DL>"
End if
bolFileFound = True
End if
objTextStream.Close
End if
End if
Next
End Sub
function Obt_Url (nompath)
obt_url = CurUrl +"/"+ right(nompath,len(nompath) - len(curpath)-1)
End function
%>
<% End if %>
</P>
</BODY></HTML>
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("SearchText"
response.write "<TITLE>Ricerca risultati per "& Request("SearchText"
Else
response.write "<TITLE>Pagina Di Ricerca </TITLE>"
End if %>
</HEAD>
<BODY>
<FORM method="post" action="search.asp">
<DIV align="center"></DIV>
<DIV align="center">
<TABLE bgcolor="#0033CC" border="0" bordercolorlight="#00FFFF" bordercolordark="#000000">
<TR>
<TD> <FONT color="#CCCCCC"> <FONT color="#FFFFFF">Ricerca</FONT>
<INPUT type="text" name="SearchText" size="40">
</FONT> </TD>
<TD> <FONT color="#CCCCCC">
<INPUT type="submit" name="Submit2" value="Cerca">
</FONT></TD>
</TR>
<TR>
<TD height="32"> <FONT color="#CCCCCC"> <FONT color="#FFFFFF">Mostra i risultati</FONT>
<Select name="rLength" >
<OPTION value="200" SELECTED>Frase
<OPTION value="100">Singola Parola
<OPTION value="0">Solo Url
</Select>
<Select name="rResults">
<OPTION value="10" SELECTED>10
<OPTION value="25">25
<OPTION value="50">50
</Select>
</FONT> </TD>
<TD height="32"> <FONT color="#CCCCCC">
<INPUT type="reset" name="Reset" value="svuota">
</FONT></TD>
</TR>
</TABLE>
</DIV>
</FORM>
<P><% if Request("SearchText"
<P><B>Risultati della ricerca per '<%=Request("SearchText"
<%
'
' 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 = ".txt .rtf .doc"
strRoot = "/"
strText = Request("SearchText"
if Request("Case"
if Request("rResults"
if Request("rResults"
if Request("rResults"
reqLength = Request("rLength"
Set objFSO = Server.CreateObject("Scripting.FileSystemObject"
Set objFolder = objFSO.GetFolder(Server.MapPath(strRoot))
CurURL= " & Request.serverVariables("SERVER_NAME"
CurPath = objFolder
schSubFol(objFolder)
For Each objSubFolder In objFolder.SubFolders
schSubFol(objSubFolder)
Next
if Not bolFileFound Then Response.Write "La ricerca non ha trovato nulla.."
if bolFileFound Then Response.Write "<B>Fine Ricerca</B>"
Set objTextStream = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
Sub schSubFol(objFolder)
For Each objFile In objFolder.Files
if Count + 1 > reqNumber or strText = "" 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, "<TITLE>",1)
if postitle > 0 Then
strTitle = Mid(strContent, postitle + 7, InStr(1, strContent, "</TITLE>", 1) - (postitle + 7))
Else
strTitle = "File"
End if
Count = Count + 1
Response.Write "<DL><DT><B><I>"& Count &"</I></B> - <A HREF="&Obt_Url(objFile.path) & ">" & strTitle & "</A></DT><BR><DD>"
strTitleL = InStr(1, strContent, "</TITLE>", 1) - InStr(1, strContent, "<TITLE>", 1) + 7
strDeTag = ""
bolTagFound = False
Do While InStr(strContent, "<"
bolTagFound = True
strDeTag = strDeTag & " " & Left(strContent, InStr(strContent, "<"
strContent = MID(strContent, InStr(strContent, ">"
Loop
strDeTag = strDeTag & strContent
if Not bolTagFound Then strDeTag = strContent
if reqLength = "0" Then
Response.Write obt_url(objFile.Path) & "</DD></DL>"
Else
Response.Write Mid(strDeTag, strTitleL, reqLength) & "...<BR><I><FONT SIZE='2'>URL: " & obt_url(objFile.Path) & " - Ultima modifica: " & objFile.DateLastModified & " - " & FormatNumber(objFile.Size / 1024) & "Kbytes</FONT></I></DD></DL>"
End if
bolFileFound = True
End if
objTextStream.Close
End if
End if
Next
End Sub
function Obt_Url (nompath)
obt_url = CurUrl +"/"+ right(nompath,len(nompath) - len(curpath)-1)
End function
%>
<% End if %>
</P>
</BODY></HTML>