How to create a customized Index Server search page by using ASP in Expression Web

Article translations Article translations
Article ID: 928700 - View products that this article applies to.
Expand all | Collapse all

On This Page

INTRODUCTION

This article describes how to create a customized Index Server search page by using Active Server Pages (ASP) in Microsoft Expression Web.

MORE INFORMATION

Step 1: Install Microsoft ASP.NET

Before you can use the ASP features in Expression Web, you must install ASP.NET. For more information about how to install ASP.NET, click the following article number to view the article in the Microsoft Knowledge Base:
928710 How to install ASP.NET to use the Active Server Pages (ASP) features in Expression Web

Step 2: Add a form page in Expression Web

  1. Start Expression Web, and then open the Web site for which you want to create a search page.
  2. On the File menu, point to New, click Page, and then click OK.
  3. On the Insert menu, point to HTML, and then click More HTML Tags.
  4. In the right pane, expand Form Controls, and then double-click Input (Text), double-click Drop-Down Box, and then double-click Input (Submit).
  5. On the Web page, double-click the text box that you inserted in step 4.
  6. In the Text Box Properties dialog box, type QUERYTEXT in the Name box.
  7. In the Initial value box, type <%=Request("QUERYTEXT")%>, and then click OK.
  8. On the Web page, double-click the drop-down box that you inserted in step 4.
  9. In the Drop Down Box Properties dialog box, type QUERYFIELD in the Name box.
  10. Click Add, and then type DocAppName in the Choice box.
  11. Click to clear the Specify Value check box, and then click OK.
  12. Repeat steps 10 and 11 to add the following menu items:
    • Characterization
    • FileName
    • DocAuthor
    • DocTitle
  13. Click OK
  14. Right-click the Submit button, and then click Form Properties.
  15. Click Send to other, and then click Options.
  16. In the Action box, type <%=Request.ServerVariables("URL")%>, and then click OK two times.
  17. On the File menu, click Save.
  18. In the File name box, type IndexServerTest.asp, and then click Save.

Step 3: Add the sample ASP code to the page

Note You may receive an error message if you paste the sample code from this article into Expression Web. Expression Web may misinterpret the angle brackets (<). To work around this behavior, paste the sample code into a blank Notepad document. Then, copy the code in Notepad, and then paste it into Expression Web.
  1. In the status bar of the right pane, click Code to switch to the HTML view.
  2. Type or paste the following code before the opening HTML tag:
    <%
      ' Force variable declaration.
      Option Explicit
    
      ' Declare all our variables.
      Dim strQueryText
      Dim strQueryField
      Dim strSQL
      Dim strName
      Dim strValue
      Dim objRS
      Dim objField
    
      ' This is the list of Index Server variables that will appear.
      ' You can customize the list of fields. For more information,
      ' see Microsoft Knowledge Base article 318387.
      Const strDisplayFields = "Rank, DocAuthor, DocAppName, DocTitle, FileName, Create, Access, Characterization, VPath"
    
      ' This is the default Index Server catalog for all Web content.
      ' For information about how to customize this, see Microsoft 
      ' Knowledge Base article 318387.
    
      Const strDataSource = "WEB"
    
      ' Get the value of the user-submitted search query.
      strQueryText = Request("QUERYTEXT")
      ' Set a default value if the user has not submitted anything.
      If Len(strQueryText) = 0 Then strQueryText = "%%"
    
      ' Get the field that the user wants to query against.
      strQueryField = Request("QUERYFIELD")
      ' Set a default value if the user has not specified a field.
      If Len(strQueryField) = 0 Then strQueryField = "DocTitle"
    %>
  3. Type or paste the following code after the closing tag:
    ' Check if the user has entered a value in the form
    If strQueryText <> "%%" Then
    <%
      ' Build the SQL statement from the user-specified options.
      strSQL = "SELECT " & strDisplayFields & " FROM SCOPE() " & _
      	"WHERE ((" & strQueryField & " LIKE '%" & strQueryText & "%') AND " & _
      	"((VPath NOT LIKE '%/_vti%') AND (VPath NOT LIKE '%/_private%')))"
    
      ' Create a recordset object.
      Set objRS = Server.CreateObject("ADODB.Recordset")
    
      ' Open the recordset by using the SQL string with the Index Server provider.
      objRS.Open strSQL,"PROVIDER=MSIDXS;DATA SOURCE=" & strDataSource
    
      ' Are there any records to show?
      If objRS.EOF Then
    
        ' Show a default message if nothing is found.
        Response.Write "No Documents were Found." & vbCrLf  
    
      ' Otherwise...
      Else
    
        ' Start a table.
        Response.Write "<table border=""1"">" & vbCrLf
    
        ' Start the row for the header section.
        Response.Write "<tr>" & vbCrLf
        ' Loop through the fields collection.
        For Each objField in objRS.Fields
          ' Get the field's name.
          strName  = objField.Name
          ' If the field has a name, escape it for HTML.
          If Len(strName)  > 0 Then strName = Server.HTMLEncode(strName)
          ' Output the field name as a table header.
          Response.Write "<th>" & strName & "</th>" & vbCrLf
        Next
        ' End the row for the header section.
        Response.Write "</tr>" & vbCrLf   
    
        ' Loop through all the records.
        While Not objRS.EOF
          ' Start a row in the data section.
          Response.Write "<tr>" & vbCrLf
          ' Loop through the fields collection.
          For Each objField in objRS.Fields
            ' Get the field's value.
            strValue = objField.Value
            ' Look for null values.
            If Len(strValue) > 0 Then
              ' If the value is not null, escape it for HTML.
              strValue = Server.HTMLEncode(strValue)
            Else
              ' Otherwise, make it a non-breaking space character.
              strValue = "&#xa0;"
            End If
          ' Output the field value as table data.
            Response.Write "<td>" & strValue & "</td>" & vbCrLf
          Next
          ' End a row in the data section.
          Response.Write "</tr>" & vbCrLf
          ' Move on to the next record.
          objRS.MoveNext
         Wend
         Response.Write "</table>" & vbCrLf
      End If
    %>
    Else
    ' User has not entered any value in search form
        Response.Write "Please enter a Search Term before submitting the form" & vbCrLf
    End if
  4. On the File menu, click Save.

Step 4: Test the sample ASP page

  1. Start Expression Web, and then open the IndexServerTest.asp page.
  2. On the File menu, point to Preview in Browser, and then click the browser that you want to use.
  3. In the text box, type your search criteria. In the list, click the field that you want to query.
  4. Click Submit. Any results that match your query appear in a table on the page.

Step 5: Customize the sample ASP page

Use either of the following methods to customize the sample ASP page.

Method 1: Change the catalog

If multiple Index Server catalogs are defined on the Web server, you can configure the sample page to use a different catalog. To do this, follow these steps:
  1. Start Expression Web, and then open the sample ASP page that you created earlier in this article.
  2. Click Code to switch to HTML view.
  3. Locate the following line of code:
    Const strDataSource = "WEB"
  4. Change the value of the strDataSource variable to the name of your catalog. For example, the line will resemble the following code:
    Const strDataSource = My_Custom_Catalog
  5. On the File menu, click Save, and then close the file.

Method 2: Modify the Field list

  1. Start Expression Web, and then open the sample Web page that you created earlier in this article.
  2. Click Code to switch to HTML view.
  3. Locate the line of code that resembles the following code:
    Const strDisplayFields = "Rank, DocAuthor, DocAppName"
  4. Change the list of values. Separate each field name with a comma. For example, the line will resemble the following code:
    Const strDisplayFields = "Rank, DocAuthor, DocAppName, DocTitle"
  5. On the File menu, click Save, and then close the file.
The following table lists the values that you can use for the strDisplayFields variable.
Collapse this tableExpand this table
Field NameField TypeDescription
AccessDate/TimeThe last time that the file was accessed
CharacterizationText/StringCharacterization, or abstract, of the document as computed by Index Server
CreateDate/TimeThe time that the file was created
DirectoryText/StringThe physical path of the file, not including the file name
DocAppNameText/StringThe name of the application that created the file
DocAuthor Text/StringThe author of the document
DocByteCountNumeric The number of bytes in the document
DocCategoryText/StringThe type of document, such as a memo, schedule, or white paper
DocCharCount NumericThe number of characters in the document
DocCommentsText/StringThe comments about the document
DocCompanyText/StringThe name of the company for which the document was written
DocCreatedTmDate/TimeThe time that the document was created
DocEditTimeDate/TimeThe total time that was spent editing the document
DocHiddenCountNumericThe number of hidden slides in a Microsoft PowerPoint presentation
DocKeywordsText/StringThe document keywords
DocLastAuthorText/StringThe most recent user who edited the document
DocLastPrintedDate/TimeThe time that the document was last printed
DocLastSavedTmDate/Time The time that the document was last saved
DocLineCountNumericThe number of lines that are contained in a document
DocManagerText/StringThe name of the manager of the document's author
DocNoteCountNumericThe number of pages that have notes in a PowerPoint presentation
DocPageCountNumericThe number of pages in the document
DocParaCountNumericThe number of paragraphs in the document
DocPartTitlesText/StringThe names of the document parts. For example, in Microsoft Excel, a spreadsheet is a document part. In Microsoft PowerPoint, a slide is a document part. In Microsoft Word, the file names of the documents that are contained in a master document are document parts.
DocPresentationTargetText/StringThe target format (such as 35mm, printer, or video) for a PowerPoint presentation
DocRevNumberText/StringThe current version number of a document
DocSlideCountNumericThe number of slides in a PowerPoint presentation
DocSubjectText/StringThe subject of the document
DocTemplateText/StringThe name of the template for the document
DocTitleText/StringThe title of the document
DocWordCountNumericThe number of words in the document
FileIndexNumericThe unique ID of the file
FileNameText/StringThe name of the file
HitCountNumericThe number of hits, or words that match a query, in the file
PathText/StringThe full physical path of the file, including file name
RankNumericThe rank of the row. This value ranges from 0 to 1000. Larger numbers indicate better matches.
ShortFileNameText/StringThe short (8.3) file name
SizeNumericThe size of the file in bytes
VPathText/StringThe full virtual path of file, including the file name. If there is more than one possible path, the best match for the specific query is chosen.
WriteDate/TimeThe last time that the file was written

Troubleshooting

  • If the Index Service is not running, you receive the following error message:
    Microsoft OLE DB Provider for Indexing Service error '80041820' Service is not running. /IndexServerTest.asp, line 44
    To resolve this problem, start the Index Service.
  • If you specify a catalog that is not valid, you receive an error message resembles the following error message:
    Microsoft OLE DB Provider for Indexing Service error '8004181d' There is no catalog. /IndexServerTest.asp, line 44
    To resolve this problem, check the value of the strDataSource variable. If it is correct, restart the Index Service.

REFERENCES

For more information about how to work with the Microsoft Windows 2000 Indexing Service, click the following article numbers to view the articles in the Microsoft Knowledge Base:
185985 Using Index Server to query and display META TAG information
256276 Error message: There is no catalog
229282 ASP code is visible when you view source of an Index Server results page

Properties

Article ID: 928700 - Last Review: December 11, 2006 - Revision: 1.0
APPLIES TO
  • Microsoft Expression Web
Keywords: 
kbhowto kbexpertiseinter KB928700

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com