Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

How to query Index Server data by using ASP in FrontPage 2002


View products that this article applies to.

This article was previously published under Q318387

↑ Back to the top


Summary

Use this step-by-step guide to create a customized Index Server search page by using Active Server Pages (ASP) in FrontPage 2002.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

Step 1 - Prepare to Use the ASP Features in FrontPage

Before you can use the ASP features in FrontPage 2002, install the components listed in the following Microsoft Knowledge Base article:
318287� What you need to use Active Server Pages (ASP) in FrontPage 2002

Step 2 - Create a Form Page in FrontPage

  1. Start FrontPage and then open a Web site on a Microsoft Windows 2000 Web Server.
  2. Click the New Page button on the Standard toolbar.
  3. On the Insert menu, point to Form, and then click Textbox.
  4. Double-click the text box. Name it QUERYTEXT. For the initial value, type:
    <%=Request("QUERYTEXT")%>
    							
    Click OK.
  5. Click after the text box.
  6. Add a drop-down list box to the form. To do this, point to Form on the Insert menu, and then click Drop-Down Box.
  7. Double-click the drop-down list box. Name it QUERYFIELD.
  8. Click Add. For choice, type DocAppName. Clear the Specify Value check box if necessary, and then click OK.
  9. Repeat step 8 to add the following menu choices:
    Characterization
    FileName
    DocAuthor
    DocTitle
  10. Click OK to close the Properties dialog box.
  11. Right-click the Submit button and click Form Properties on the menu that appears.
  12. Click the Send to other option, and then click Options.
  13. In the Action box, type the following:
    <%=Request.ServerVariables("URL")%>
    							
    Click OK.
  14. Save the page and name it IndexServerTest.asp.

Step 3 - Add the Sample ASP Code to the Page

NOTE: You may receive an error message if you copy the examples directly from this article and paste them into FrontPage. The angle brackets (< and >) may appear as escaped HTML code (< and >). To work around this behavior, paste the script into a blank Notepad document, and then copy it from Notepad before you paste it into FrontPage.
  1. Switch to 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.
      ' NOTE: You can customize the list of fields. For more information,
      ' see Microsoft Knowledge Base article Q318387.
      Const strDisplayFields = "Rank, DocAuthor, DocAppName, DocTitle, FileName, Create, Access, Characterization, VPath"
    
      ' This is the default index server catalog for all Web content.
      ' NOTE: For information about how to customize this, see Microsoft 
      ' Knowledge Base article Q318387.
    
      Const strDataSource = "WEB"
    
      ' Get the value of the user-submitted search query.
      strQueryText = Request("QUERYTEXT")
      ' Set a default value if the user has not sumitted anything.
      If Len(strQueryText) = 0 Then strQueryText = "N/A"
    
      ' Get the field 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 </FORM> tag:
    <%
      ' 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 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
            ' Check 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
    %>
    					
  4. Switch back to Normal view.
  5. Save the file.

Step 4 - Test the Sample ASP Page

  1. Open the sample page in FrontPage.
  2. Click the Preview in Browser button on the Standard toolbar.
  3. Type some search criteria in the text box.
  4. From the drop-down menu, choose the field that you want to query.
  5. Click Submit.
Any results that match your query appear in a table on the page.

Step 5 - Customize the Sample ASP Page

There are two customization options:
  • Changing the Catalog
  • Modifying the Field List

To Change the Catalog

If multiple Index Server catalogs are defined on your Web server, you can specify that the sample page use a different catalog. To do this, follow these steps:
  1. In FrontPage, open the sample page.
  2. Switch to HTML view.
  3. Locate the following line of code:
    Const strDataSource = "WEB"
    					
  4. Change the value of strDataSource to the name of your catalog, similar to this:
    Const strDataSource = "MyCustomCatalog"
    					
  5. Save and close the file.

To Modify the Field List

  1. In FrontPage, open the sample page.
  2. Switch to HTML view.
  3. Locate the line of code that looks similar to this:
    Const strDisplayFields = "Rank, DocAuthor, DocAppName"
    					
  4. Modify the list of values. Separate each field name with a comma, like this:
    Const strDisplayFields = "Rank, DocAuthor, DocAppName, DocTitle"
    					
  5. Save and close the file.
The following table lists the values you can use for the strDisplayFields variable.

Field Name              Field Type    Description 
---------------------------------------------------------------------------
Access                  Date/Time     Last time file was accessed. 

Characterization        Text/String   Characterization, or abstract, of 
                                      document. Computed by Index Server. 

Create                  Date/Time     Time file was created. 

Directory               Text/String   Physical path to the file, not 
                                      including the file name. 

DocAppName              Text/String   Name of application that created the 
                                      file. 

DocAuthor               Text/String   Author of the document. 

DocByteCount            Numeric       Number of bytes in the document. 

DocCategory             Text/String   Type of document, such as a memo, 
                                      schedule, or white paper. 

DocCharCount            Numeric       Number of characters in the document. 

DocComments             Text/String   Comments about the document. 

DocCompany              Text/String   Name of the company for which the 
                                      document was written. 

DocCreatedTm            Date/Time     Time document was created. 

DocEditTime             Date/Time     Total time spent editing document. 

DocHiddenCount          Numeric       Number of hidden slides in a 
                                      PowerPoint file. 

DocKeywords             Text/String   Document keywords. 

DocLastAuthor           Text/String   Most recent user who edited the
                                      document. 

DocLastPrinted          Date/Time     Time document was last printed. 

DocLastSavedTm          Date/Time     Time document was last saved. 

DocLineCount            Numeric       Number of lines contained in a 
                                      document. 

DocManager              Text/String   Name of the manager of the document's
                                      author. 

DocNoteCount            Numeric       Number of pages with notes in a 
                                      PowerPoint file. 

DocPageCount            Numeric       Number of pages in th document. 

DocParaCount            Numeric       Number of paragraphs in the document. 

DocPartTitles           Text/String   Names of document parts. For example, 
                                      in Microsoft Excel, a spreadsheet is 
                                      a document part. In PowerPoint, a 
                                      slide is a document part. And, in 
                                      Word, the file names of the documents 
                                      contained in a master document are 
                                      document parts.

DocPresentationTarget   Text/String   Target format (35mm, printer, video,
                                      and so on) for a PowerPoint 
                                      presentation.

DocRevNumber            Text/String   Current version number of a document. 

DocSlideCount           Numeric       Number of slides in a PowerPoint 
                                      file. 

DocSubject              Text/String   Subject of the document. 

DocTemplate             Text/String   Name of the template for the 
                                      document. 

DocTitle                Text/String   Title of document. 

DocWordCount            Numeric       Number of words in the document. 

FileIndex               Numeric       Unique ID of the file. 

FileName                Text/String   Name of the file. 

HitCount                Numeric       Number of hits (words matching query)
                                      in the file. 

Path                    Text/String   Full physical path to the file, 
                                      including file name. 

Rank                    Numeric       Rank of row. Ranges from 0 to 1000. 
                                      Larger numbers indicate better 
                                      matches. 

ShortFileName           Text/String   Short (8.3) file name. 

Size                    Numeric       Size of file, in bytes. 

VPath                   Text/String   Full virtual path to file, including 
                                      file name. If more than one possible
                                      path, then the best match for the 
                                      specific query is chosen. 

Write                   Date/Time     Last time file was written. 

				

Troubleshooting

  • If the Index Service is not running, the following error message appears:
    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 an invalid catalog, an error message similar to the following appears:
    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.

↑ Back to the top


References

For more information about working with the 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

↑ Back to the top


Keywords: KB318387, kbhowtomaster, kbprogramming, kbasp

↑ Back to the top

Article Info
Article ID : 318387
Revision : 6
Created on : 2/1/2007
Published on : 2/1/2007
Exists online : False
Views : 387