 |
| Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

February 6th, 2006, 07:21 AM
|
|
Authorized User
|
|
Join Date: Feb 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Regarding Search Tool in ASP Page.Urgent Help Need
I have Pasted the asp file.The problem is if i have the pdf document and i search the Pdf doc by its name in the Search textbox i couldn't able to search But in case of Word document i could able to do in the same way.And if gave *.* in the text box its showing all pdf and .doc files.And all the files(doc and Pdf are save in the Vir. Folder ie., along with the asP file) are saved in the virtual folder,Could u please Help me solve the Issue.
code is search1.asp
<% Option Explicit %>
<%
'Set the response buffer to true
Response.Buffer = False
'Dimension global variables
Dim fsoObject 'File system object
Dim fldObject 'Folder object
Dim sarySearchWord 'Array to hold the words to be searched for
Dim strSearchWords 'Holds the search words
Dim blnIsRoot 'Set to true if we are searching in the root directory
Dim strFileURL 'Holds the path to the file on the site
Dim strServerPath 'Holds the server path to this script
Dim intNumFilesShown 'Holds the number of files shown so far
Dim intTotalFilesSearched 'Holds the number of files searched
Dim intTotalFilesFound 'Holds the total matching files found
Dim intFileNum 'Holds the file number
Dim intPageLinkLoopCounter 'Loop counter to display links to the other result pages
Dim sarySearchResults(1000,2) 'Two Dimensional Array holding the search results
Dim intDisplayResultsLoopCounter 'loop counter to diplay the results of the search
Dim intResultsArrayPosition 'Stores the array position of the array storing the results
Dim blnSearchResultsFound 'Set to true if search results are found
Dim strFilesTypesToSearch 'Holds the types of files to be searched
Dim strBarredFolders 'Holds the folders that you don't want searched
Dim strBarredFiles 'Holds the names of the files not to be searched
Dim blnEnglishLanguage 'Set to True if the user is using English
' -------------------------- Change the following line to the number of results you wish to have on each page ------------------------------------
Const intRecordsPerPage = 10 'change this to the number of results to show on each page
' --------------------- Place the names of the files types you want searching in the following line sepeararted by commas --------------------------
strFilesTypesToSearch = "pdf,doc"
',htm,html,asp,shtml,pdf,txt
' --------------------- Place the names of the folders you don't want searched in the following line spearated by commas --------------------------
strBarredFolders = "cgi_bin,_bin" 'cgi_bin and _bin have been put in here as examples, but you can put any folders in here
' ---------- Place the names of the files you don't want searched in the following line spearated by commas include the file extension -------------
strBarredFiles = "adminstation.htm,no_allowed.asp" 'adminstration.htm and not_allowed.asp have been put in as an examples
' -------------------- Set this boolean to False if you are not using an English language web site --------------------------------------------------
blnEnglishLanguage = True 'True = HTML Encode best for English sites \ False = no Emcoding best for non English sites
'-----------------------------------------------------------------------------------------------------------------------------------------------------
'Initalise variables
intTotalFilesSearched = 0
%>
<HTML>
<HEAD>
<TITLE>Head Office Product & Marketing Intranet Homepage</TITLE>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<LINK href="rstyles.css" type="text/css" rel="stylesheet">
<script language="JavaScript">
<!-- Hide from older browsers...
//Preload search icon
var search_icon_off = new Image();
search_icon_off.src = "site_search_icon_off.gif";
//Check the form before submitting
function CheckForm () {
//Check for a word to search
if (document.frmSiteSearch.search.value=="")
{
alert("Please enter at least one keyword to search");
document.frmSiteSearch.search.focus();
return false;
}
return true
}
// -->
</script>
<META content="MSHTML 6.00.2800.1400" name="GENERATOR"></HEAD>
<BODY>
<DIV class="margins">
<table cellspacing="0" cellpadding="0" width="800" border="0">
<tbody>
<tr>
<td class="leftPurpleBar" valign="top" width="25" rowspan="2"><img height="67" alt="" src="images/template/leftbordertop2.gif" width="25"></td>
<td class="leftGreyBar" width="15"> </td>
<td width="5"> </td>
<td width="5"><img height="1" alt="" src="images/template/spacer.gif" width="5"></td>
<td class="leftPinkBar" width="5"> </td>
<td width="5"><img height="1" alt="" src="images/template/spacer.gif" width="5"></td>
<td colspan="2"> </td>
</tr>
<tr>
<td class="leftGreyBar" width="15"><img height="8" alt="" src="images/template/spacer.gif" width="15"></td>
<td>
<div>
<div>
<div align="center"><img height="50" alt="SHL" src="images/template/shllogostrap.gif" width="83"></div>
</div>
</div>
</td>
<td width="5"><img height="1" alt="" src="images/template/spacer.gif" width="5"></td>
<td class="leftPinkBar" width="5"><img height="1" alt=" " src="images/template/spacer.gif" width="5"></td>
<td width="5"><img height="1" alt=" " src="images/template/spacer.gif" width="5"></td>
<td colspan="2" valign="bottom">
<h1>Search</h1>
</td>
<td height="50" valign="center">
</td>
</tr>
<tr>
<td class="leftPurpleBar" width="25"> </td>
<td class="leftGreyBar" width="15"> </td>
<td class="whiteBG"><img height="2" alt=" " src="images/template/pinkline.gif" width="180"></td>
<td width="5"><img height="1" alt="" src="images/template/spacer.gif" width="5"></td>
<td class="leftPinkBar" width="5"> </td>
<td class="whiteBG" width="5"> </td>
</tr>
<tr>
<td class="leftPurpleBar" height="30" width="25"> </td>
<td class="leftGreyBar" height="30" width="15"> </td>
<td class="whiteBG" height="30"><img height="8" alt=" " src="images/template/spacer.gif" width="180"></td>
<td width="5"><img height="1" alt="" src="images/template/spacer.gif" width="5"></td>
<td class="leftPinkBar" height="30" width="5"> </td>
<td class="whiteBG" height="30" width="5"> </td>
</tr>
<tr>
<td class="leftPurpleBar" height="30" width="25" valign="bottom"><img height="47" alt=" " src="images/template/leftborderbottom_r1_c1.gif" width="25"></td>
<td class="leftGreyBar" height="30" width="15"> </td>
<td class="whiteBG" height="30" valign="top" bgcolor="#cccccc"><a href="index.htm"><b>Home</b></a><b><span class="menuSeparator"></span><a href="contact.htm"><br>
<br>
Contacts</a><span class="menuSeparator"></span><a href="org-chart.htm"><br>
<br>
Organisation Chart<br>
</a><a href="corp-communications/index.htm">
<br>
Corporate Communications</a><span class="menuSeparator"></span><a href="marketing/index.htm"><br>
<br>
Corporate Marketing</a><span class="menuSeparator"></span><a href="design-innovation/index.htm"><br>
<br>
Design & Innovation<br>
</a></b><b><a href="product-management/index.htm">
<br>
Product Management</a><span class="menuSeparator"></span><a href="production-operations/index.htm"><br>
<br>
Production & Operations</a><span class="menuSeparator"></span><a href="http://oberon/groupr&d/home/index.htm"><br>
<br>
Research</a>
<span class="menuSeparator"></span><a href="search1.asp"><br>
<br>
Search</a> </b>
</td>
<td width="5"><img height="1" alt="" src="images/template/spacer.gif" width="5"></td>
<td class="leftPinkBar" height="30" width="5"> </td>
<td class="whiteBG" height="30" width="5"> </td>
<td valign="top" colspan="2">
<p>
<form method="get" name="frmSiteSearch" action="search1.asp" onSubmit="return CheckForm();" ID="Form1">
<table cellpadding="0" cellspacing="0" width="730" align="center" ID="Table1" height="77">
<tr>
<td class="arial" height="4" width="571">
Search the Web Site:
</td>
</tr>
<tr>
<td class="normal" height="2" width="571">
<input type="TEXT" name="search" maxlength="50" size="36" value="<% =Request.QueryString("search") %>" ID="Text1">
Anand <input type="submit" value="Search >>" name="submit" ID="Submit1">
</td>
</tr>
<tr>
<td class="normal" height="34" width="571" valign="top">
Search On : <input type="radio" name="mode" value="allwords" CHECKED ID="Radio1">
All Words <input type="radio" name="mode" value="anywords" ID="Radio2"> Any
Words </td>
</tr>
</table>
</form>
<%
'Read in all the search words into one variable
strSearchWords = Trim(Request.QueryString("search"))
'If the site is in English then use the server HTML encode method
If blnEnglishLanguage = True Then
'Replace any HTML tags with the HTML codes for the same characters (stops people entering HTML tags)
strSearchWords = Server.HTMLEncode(strSearchWords)
'If the site is not english just change the script tags
Else
'Just replace the script tag <> with HTML encoded < and >
strSearchWords = Replace(strSearchWords, "<", "<", 1, -1, 1)
strSearchWords = Replace(strSearchWords, ">", ">", 1, -1, 1)
End If
'Slit each word to be searched up and place in an array
sarySearchWord = Split(Trim(strSearchWords), " ")
'Read the file number to show from
intFileNum = CInt(Request.QueryString("FileNumPosition"))
'Set the number of files shown so far to the file number read in above
intNumFilesShown = intFileNum
'Create the file system object
Set fsoObject = Server.CreateObject("Scripting.FileSystemObject")
'If there is no words entered by the user to search for then dont carryout the file search routine
If NOT strSearchWords = "" Then
'Get the path and the root folder to be searched
Set fldObject = fsoObject.GetFolder(Server.MapPath("./"))
'Read in the server path to this ASP script
strServerPath = fldObject.Path & "\"
'Set to true as this is searching the root directory
blnIsRoot = True
'Call the search sub prcedure
Call SearchFile(fldObject)
'Reset server variables
Set fsoObject = Nothing
Set fldObject = Nothing
'Call the Bubble Sort procedure to sort the results into highest matches first
Call SortResultsByNumMatches(sarySearchResults, intTotalFilesFound)
'Display the HTML table with the results status of the search or what type of search it is
Response.Write vbCrLf & " <table width=""98%"" border=""0"" cellspacing=""1"" cellpadding=""1"" align=""center"" bgcolor=""#CCCCCC"">"
Response.Write vbCrLf & " <tr>"
'Display that there where no matching records found
If blnSearchResultsFound = False Then
Response.Write vbCrLf & " <td> Searched the site for <b>" & strSearchWords & "</b>. Sorry, no results found.</td>"
'Else Search went OK so display how many records found
Else
Response.Write vbCrLf & " <td> Searched the site for <b>" & strSearchWords & "</b>. Displaying Results " & intFileNum + 1 & " - " & intNumFilesShown & " of " & intTotalFilesFound & ".</td>"
End If
'Close the HTML table with the search status
Response.Write vbCrLf & " </tr>"
Response.Write vbCrLf & " </table>"
'HTML table to display the search results or an error if there are no results
Response.Write vbCrLf & " <table width=""95%"" border=""0"" cellspacing=""1"" cellpadding=""1"" align=""center"">"
Response.Write vbCrLf & " <tr>"
Response.Write vbCrLf & " <td>"
'If no results are found then display an error message
If blnSearchResultsFound = False Then
'Write HTML displaying the error
Response.Write vbCrLf & " <br>"
Response.Write vbCrLf & " Your Search - <b>" & strSearchWords & "</b> - did not match any files on this site."
Response.Write vbCrLf & " <br><br>"
Response.Write vbCrLf & " Suggestions:"
Response.Write vbCrLf & " <br>"
Response.Write vbCrLf & "[list]<li>Make sure all words are spelled correctly.<li>Try different keywords.<li>Try more general keywords.<li>Try fewer keywords.</ul>"
'Else display the results
Else
'Loop round to display each result within the search results array
For intDisplayResultsLoopCounter = (intFileNum + 1) to intNumFilesShown
Response.Write vbCrLf & " <br>"
Response.Write vbCrLf & " " & sarySearchResults(intDisplayResultsLoopCounter,1)
Response.Write vbCrLf & " <br>"
Next
End If
'Close the HTML table displaying the results
Response.Write vbCrLf & " </td>"
Response.Write vbCrLf & " </tr>"
Response.Write vbCrLf & " </table>"
End If
'Display an HTML table with links to the other search results
If intTotalFilesFound > intRecordsPerPage then
'Display an HTML table with links to the other search results
Response.Write vbCrLf & " <br>"
Response.Write vbCrLf & " <table width=""100%"" border=""0"" cellspacing=""0"" cellpadding=""0"" align=""center"">"
Response.Write vbCrLf & " <tr>"
Response.Write vbCrLf & " <td>"
Response.Write vbCrLf & " <table width=""100%"" border=""0"" cellpadding=""0"" cellspacing=""0"">"
Response.Write vbCrLf & " <tr>"
Response.Write vbCrLf & " <td width=""50%"" align=""center"">"
Response.Write vbCrLf & " Results Page: "
'If the page number is higher than page 1 then display a back link
If intNumFilesShown > intRecordsPerPage Then
Response.Write vbCrLf & " <a href=""search1.asp?FileNumPosition=" & intFileNum - intRecordsPerPage & "&search=" & Replace(strSearchWords, " ", "+") & "&mode=" & Request.QueryString("mode") & """ target=""_self""><< Prev</a> "
End If
'If there are more pages to display then display links to all the search results pages
If intTotalFilesFound > intRecordsPerPage Then
'Loop to diplay a hyper-link to each page in the search results
For intPageLinkLoopCounter = 1 to CInt((intTotalFilesFound / intRecordsPerPage) + 0.5)
'If the page to be linked to is the page displayed then don't make it a hyper-link
If intFileNum = (intPageLinkLoopCounter * intRecordsPerPage) - intRecordsPerPage Then
Response.Write vbCrLf & " " & intPageLinkLoopCounter
Else
Response.Write vbCrLf & " <a href=""search1.asp?FileNumPosition=" & (intPageLinkLoopCounter * intRecordsPerPage) - intRecordsPerPage & "&search=" & Replace(strSearchWords, " ", "+") & "&mode=" & Request.QueryString("mode") & """ target=""_self"">" & intPageLinkLoopCounter & "</a> "
End If
Next
End If
'If it is Not the last of the search results than display a next link
If intTotalFilesFound > intNumFilesShown then
Response.Write vbCrLf & " <a href=""search1.asp?FileNumPosition=" & intNumFilesShown & "&search=" & Replace(strSearchWords, " ", "+") & "&mode=" & Request.QueryString("mode") & """ target=""_self"">Next >></a>"
End If
'Finsh HTML the table
Response.Write vbCrLf & " </td>"
Response.Write vbCrLf & " </tr>"
Response.Write vbCrLf & " </table>"
Response.Write vbCrLf & " </td>"
Response.Write vbCrLf & " </tr>"
Response.Write vbCrLf & " </table>"
End If
%>
<br>
<div align="center">
<table width="98%" border="0" cellspacing="1" cellpadding="1" bgcolor="#CCCCCC" align="center" ID="Table2">
<tr>
<td width="47%" height="18"> Searched
<% = intTotalFilesSearched %>
documents in total.
</td>
<td width="53%" align="right" height="18"><%
%>
</td>
</tr>
</table>
<%
'Sub procedure to do the search
Public Sub SearchFile(fldObject)
'Dimension local variabales
Dim objRegExp 'Regular Expersions object
Dim objMatches 'Holds the matches collection of the regular expresions object
Dim filObject 'File object
Dim tsObject 'Text stream object
Dim subFldObject 'Sub folder object
Dim strFileContents 'Holds the contents of the file being searched
Dim strPageTitle 'Holds the title of the page
Dim strPageDescription 'Holds the description of the page
Dim strPageKeywords 'Holds the keywords of the page
Dim intSearchLoopCounter 'Loop counter to search all the words in the array
Dim intNumMatches 'Holds the number of matches
Dim blnSearchFound 'Set to true if the search words are found
'Error handler
On Error Resume Next
'Set the error object to 0
Err.Number = 0
'Create the regular expresions object
Set objRegExp = New RegExp
'If an error has occured then the server does not support Regular Expresions
If Err.Number <> 0 Then
Response.Write("<br>Error The Server does not support the Regular Expessions object")
'Reset error object
Err.Number = 0
End If
'Loop to search each file in the folder
For Each filObject in fldObject.Files
'Check the file extension to make sure the file is of the extension type to be searched
If InStr(1, strFilesTypesToSearch, fsoObject.GetExtensionName(filObject.Name), vbTextCompare) > 0 Then
Response.Write(filObject.name)
'Check to make sure the file about to be searched is not a barred file if it is don't search the file
If NOT InStr(1, strBarredFiles, filObject.Name, vbTextCompare) > 0 Then
'Initalise the search found variable to flase
blnSearchFound = False
'Initalise the number of matches variable
intNumMatches = 0
'Set the regular exprsion object to read all cases of the occurance not just the first
objRegExp.Global = True
'Set the regular expression object to ignore case
objRegExp.IgnoreCase = True
'Open the file for searching
Set tsObject = filObject.OpenAsTextStream
'Read in the contents of the file
strFileContents = tsObject.ReadAll
'Read in the title of the file
strPageTitle = GetFileMetaTag("<title>", "</title>", strFileContents)
'Read in the description meta tag of the file
strPageDescription = GetFileMetaTag("<meta name=""description"" content=""", """>", strFileContents)
'Read in the keywords of the file
strPageKeywords = GetFileMetaTag("<meta name=""keywords"" content=""", """>", strFileContents)
Response.Write(strPageKeywords)
'Set the pattern using regular expressions to srip any HTML tags
objRegExp.Pattern = "<[^>]*>"
'Strip HTML tags from the contects of the file to be searched
strFileContents = objRegExp.Replace(strFileContents,"")
'Put the tittle, description and the keywords back into the file to be searched
strFileContents = strFileContents & " " & strPageTitle & " " & strPageDescription & " " & strPageKeywords
'If the user has choosen to search by phrase
If Request.QueryString("mode") = "phrase" Then
'Set the pattern to search for
objRegExp.Pattern = "\b" & strSearchWords & "\b"
'Search the file for the phrase
Set objMatches = objRegExp.Execute(strFileContents)
'Check to see if the phrase has been found
If objMatches.Count > 0 Then
'Get the number of times the phrase is matched
intNumMatches = objMatches.Count
'If the search is found then set the search found variable to true
blnSearchFound = True
End If
'Else the search is either by all or any words
Else
'If the search is by all words then initialise the search found variable to true
If Request.QueryString("mode") = "allwords" then blnSearchFound = True
'Loop round to search for each word to be searched
For intSearchLoopCounter = 0 to UBound(sarySearchWord)
'Set the pattern to search for
objRegExp.Pattern = "\b" & sarySearchWord(intSearchLoopCounter) & "\b"
'Search the file for the
|
|

February 6th, 2006, 08:19 PM
|
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
|
|
To get the best help you should post problematic code only with specific problems, exact errors and if possible indicate which line it occurs.
Wind is your friend
Matt
|
|

February 7th, 2006, 05:03 AM
|
|
Authorized User
|
|
Join Date: Feb 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Mathew,
The Logical Part of the Program lies here.
The Documents for eg. Test.doc ,Sample.doc, a.pdf,b.pdf is present is the root Folder(ie., Virtual Directory).
The Search Tool which i designed should have to find the File Name and not the Contents in the File Name,For Eg) if i give a,then the results should be only a.pdf and if i give test then the results should be test.doc.
The Problem i found is with the Pattern which i specified in the following Program ,could u please help me solve that and if u need further clarification the whole program is in my 1st Posting and u have a look at it if u need any clarification.
The second Problem is in using Text Search,i need to replace so that it need to only search the File Name and not the Contents.
So plz help me solve the problem.
The Program logic is below.
Public Sub SearchFile(fldObject)
'Dimension local variabales
Dim objRegExp 'Regular Expersions object
Dim objMatches 'Holds the matches collection of the regular expresions object
Dim filObject 'File object
Dim tsObject 'Text stream object
Dim subFldObject 'Sub folder object
Dim strFileContents 'Holds the contents of the file being searched
Dim strPageTitle 'Holds the title of the page
Dim strPageDescription 'Holds the description of the page
Dim strPageKeywords 'Holds the keywords of the page
Dim intSearchLoopCounter 'Loop counter to search all the words in the array
Dim intNumMatches 'Holds the number of matches
Dim blnSearchFound 'Set to true if the search words are found
'Error handler
On Error Resume Next
'Set the error object to 0
Err.Number = 0
'Create the regular expresions object
Set objRegExp = New RegExp
'If an error has occured then the server does not support Regular Expresions
If Err.Number <> 0 Then
Response.Write("<br>Error The Server does not support the Regular Expessions object")
'Reset error object
Err.Number = 0
End If
'Loop to search each file in the folder
For Each filObject in fldObject.Files
'Check the file extension to make sure the file is of the extension type to be searched
If InStr(1, strFilesTypesToSearch, fsoObject.GetExtensionName(filObject.Name), vbTextCompare) > 0 Then
'Check to make sure the file about to be searched is not a barred file if it is don't search the file
If NOT InStr(1, strBarredFiles, filObject.Name, vbTextCompare) > 0 Then
'Initalise the search found variable to flase
blnSearchFound = False
'Initalise the number of matches variable
intNumMatches = 0
'Set the regular exprsion object to read all cases of the occurance not just the first
objRegExp.Global = True
'Set the regular expression object to ignore case
objRegExp.IgnoreCase = True
'Open the file for searching
Set tsObject = filObject.OpenAsTextStream
'Read in the contents of the file
strFileContents = tsObject.ReadAll
'Read in the title of the file
strPageTitle = GetFileMetaTag("<title>", "</title>", strFileContents)
'Read in the description meta tag of the file
strPageDescription = GetFileMetaTag("<meta name=""description"" content=""", """>", strFileContents)
'Read in the keywords of the file
strPageKeywords = GetFileMetaTag("<meta name=""keywords"" content=""", """>", strFileContents)
'Set the pattern using regular expressions to srip any HTML tags
objRegExp.Pattern = "<[^>]*>"
'Strip HTML tags from the contects of the file to be searched
strFileContents = objRegExp.Replace(strFileContents,"")
'Put the tittle, description and the keywords back into the file to be searched
strFileContents = strFileContents & " " & strPageTitle & " " & strPageDescription & " " & strPageKeywords
'If the user has choosen to search by phrase
If Request.QueryString("mode") = "phrase" Then
'Set the pattern to search for
objRegExp.Pattern = "\b" & strSearchWords & "\b"
'Search the file for the phrase
Set objMatches = objRegExp.Execute(strFileContents)
'Check to see if the phrase has been found
If objMatches.Count > 0 Then
'Get the number of times the phrase is matched
intNumMatches = objMatches.Count
'If the search is found then set the search found variable to true
blnSearchFound = True
End If
'Else the search is either by all or any words
Else
'If the search is by all words then initialise the search found variable to true
If Request.QueryString("mode") = "allwords" then blnSearchFound = True
'Loop round to search for each word to be searched
For intSearchLoopCounter = 0 to UBound(sarySearchWord)
'Response.Write "Val is " & strSearchWords & "<br>"
'Set the pattern to search for
objRegExp.Pattern = "\b" & sarySearchWord(intSearchLoopCounter) & "\b"
'Response.Write "Value is :" + objRegExp.Pattern + ":<br>"
'Search the file for the search words
'Set objMatches = objRegExp.Execute(strFileContents)
Set objMatches = objRegExp.Execute(sarySearchWord)
'Check to see if any of the words have been found
If objMatches.Count > 0 Then
'Get the number of times the search word is matched
intNumMatches = intNumMatches + objMatches.Count
'If the search word is found and the search is for any words then set the search found variable to true
If Request.QueryString("mode") = "anywords" then blnSearchFound = True
Else
'If the search word is not found and the search is for all words then set the search found variable back to false as one of the words has not been found
If Request.QueryString("mode") = "allwords" then blnSearchFound = False
End If
Next
End If
'Calculate the total files searched
intTotalFilesSearched = intTotalFilesSearched + 1
'If the page contains no title then Page Title variable the appropriate message to display
If strPageTitle = "" Then strPageTitle = filObject.Name
'"No Title"
'If the page contains no title then Page Description variable the appropriate message to display(commented)
'If strPageDescription = "" Then strPageDescription = "There is no description available for this page"
'If the search found variable is true then display the results
If blnSearchFound = True Then
'Calculate the total files found
intTotalFilesFound = intTotalFilesFound + 1
'Check that the file shown is between the the files shown so far and the maximum files to show per page
If intNumFilesShown < (intRecordsPerPage + intFileNum) and intTotalFilesFound > intNumFilesShown Then
'Calculate the number of results shown
intNumFilesShown = intNumFilesShown + 1
End If
'Place the search results into the saerch results array
'Calculate the array position of the results array
intResultsArrayPosition = intResultsArrayPosition + 1
'Set the search results found boolean to true
blnSearchResultsFound = True
'If the file is in the root directory then
If blnIsRoot = True Then
'Place the search results into the search results array
IF strPageTitle <> "No Title" THEN
sarySearchResults(intResultsArrayPosition,1) = "<a href=""./" & filObject.Name & """ target=""_self"">" & strPageTitle & "</a>"
ELSE
sarySearchResults(intResultsArrayPosition,1) = "<a href=""./" & filObject.Name & """ target=""_self"">" & filObject.Name & "</a>"
END IF
'Else it is not in the root directiory
Else
'Place the search results into the search results array
sarySearchResults(intResultsArrayPosition,1) = "<a href=""./" & strFileURL & fldObject.Name & "/" & filObject.Name & """ target=""_self"">" & strPageTitle & "</a>"
End If
'Place the rest of the search results in the search results array(commented)
'sarySearchResults(intResultsArrayPosition,1) = sarySearchResults(intResultsArrayPosition,1) & vbCrLf & " <br>" & strPageDescription
'sarySearchResults(intResultsArrayPosition,1) = sarySearchResults(intResultsArrayPosition,1) & vbCrLf & " <br><i>Search Matches " & intNumMatches & " - Last Updated " & FormatDateTime(filObject.DateLastModified, VbLongDate) & " - Size " & CInt(filObject.Size / 1024) & "kb</i>"
'Read in the number of search word matches into the second part of the two dimensional array
sarySearchResults(intResultsArrayPosition,2) = intNumMatches
End If
'Close the text stream object
tsObject.Close
End If
End If
Next
'Reset the Regular Expression object
Set objRegExp = Nothing
'Loop to search through the sub folders within the site
For Each subFldObject In FldObject.SubFolders
'Check to make sure the folder about to be searched is not a barred folder if it is then don't search
If NOT InStr(1, strBarredFolders, subFldObject.Name, vbTextCompare) > 0 Then
'Set to false as we are searching sub directories
blnIsRoot = False
'Get the server path to the file
strFileURL = fldObject.Path & "\"
'Turn the server path to the file into a URL path to the file
strFileURL = Replace(strFileURL, strServerPath, "")
'Replace the NT backslash with the internet forward slash in the URL to the file
strFileURL = Replace(strFileURL, "\", "/")
'Encode the file name and path into the URL code method
strFileURL = Server.URLEncode(strFileURL)
'Just incase it's encoded any backslashes
strFileURL = Replace(strFileURL, "%2F", "/")
'Call the search sub prcedure to search the web site
Call SearchFile(subFldObject)
End If
Next
'Reset server variables
Set filObject = Nothing
Set tsObject = Nothing
Set subFldObject = Nothing
End Sub
%>
|
|
 |