Microsoft KB Archive/927151

= How to create a custom Index Server search page by using ASP in SharePoint Designer 2007 =

Article ID: 927151

Article Last Modified on 10/15/2007

-

APPLIES TO


 * Microsoft Office SharePoint Designer 2007

-



INTRODUCTION
This step-by-step article describes how to create a custom Index Server search page by using Active Server Pages (ASP) in Microsoft Office SharePoint Designer 2007.



MORE INFORMATION
To create a custom Index Server search page by using ASP in SharePoint Designer 2007, follow these steps.

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. However, 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 SharePoint Designer 2007
Before you can use the ASP features in SharePoint Designer 2007, you must install the components that are listed in the following Microsoft Knowledge Base article:

318287 What you need to use Active Server Pages (ASP) in FrontPage 2002

Step 2: Add a form page in SharePoint Designer 2007
To do this, follow these steps:
 * 1) Start SharePoint Designer 2007, and then open the Web site.
 * 2) Click the New Document button on the toolbar.
 * 3) At the bottom of the document, click Design to switch to the Design view.
 * 4) In the Toolbox, expand Form Controls, and then double-click Form.
 * 5) In the Toolbox, expand Form Controls, and then double-click Input (Text).
 * 6) Double-click the text box that you added in step 5.
 * 7) In the Text Box Properties dialog box, type QUERYTEXT in the Name text box.
 * 8) In the Initial value box, type <%=Request(&quot;QUERYTEXT&quot;)%>, and then click OK.
 * 9) In the Toolbox, expand Form Controls, and then double-click Drop-Down Box.
 * 10) Double-click the drop-down box.
 * 11) In the Drop Down Box Properties dialog box, type QUERYFIELD in the Name text box.
 * 12) Click Add, and then type DocAppName in the Choice text box.
 * 13) Click to clear the Specify Value check box, and then click OK.
 * 14) Repeat steps 12 and 13 to add the following menu items:
 * 15) * Characterization
 * 16) * FileName
 * 17) * DocAuthor
 * 18) * DocTitle
 * 19) Click OK to close the Drop Down Box Properties dialog box.
 * 20) In the Toolbox, expand Form Controls, and then double-click Input (Submit).
 * 21) Right-click Input (Submit), and then click Form Properties.
 * 22) Click Send to other, and then click Options.
 * 23) In the Action text box, type <%=Request.ServerVariables(&quot;URL&quot;)%>, and then click OK two times.
 * 24) On the File menu, click Save.
 * 25) In the File name text 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 copy the script examples directly from this article and then paste them into SharePoint Designer 2007. SharePoint Designer 2007 may misinterpret the angle brackets. To work around this behavior, copy the script and then paste it into a blank Notepad document. Then, copy the script from Notepad, and then paste it into SharePoint Designer 2007.

To add the sample ASP code to the page, follow these steps:  At the bottom of the document, click Code to switch to HTML view.  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 = &quot;Rank, DocAuthor, DocAppName, DocTitle, FileName, Create, Access, Characterization, VPath&quot;

' 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 = &quot;WEB&quot;

' Get the value of the user-submitted search query. strQueryText = Request(&quot;QUERYTEXT&quot;) ' Set a default value if the user has not submitted anything. If Len(strQueryText) = 0 Then strQueryText = &quot;%%&quot;

' Get the field that the user wants to query against. strQueryField = Request(&quot;QUERYFIELD&quot;) ' Set a default value if the user has not specified a field. If Len(strQueryField) = 0 Then strQueryField = &quot;DocTitle&quot; %>   Type or paste the following code after the closing tag. <% ' Check if the user has entered a value in the form If strQueryText <> &quot;%%&quot; Then

' Build the SQL statement from the user-specified options. strSQL = &quot;SELECT &quot; & strDisplayFields & &quot; FROM SCOPE &quot; & _ &quot;WHERE ((&quot; & strQueryField & &quot; LIKE '%&quot; & strQueryText & &quot;%') AND &quot; & _   &quot;((VPath NOT LIKE '%/_vti%') AND (VPath NOT LIKE '%/_private%')))&quot;

' Create a recordset object. Set objRS = Server.CreateObject(&quot;ADODB.Recordset&quot;)

' Open the recordset by using the SQL string with the Index Server provider. objRS.Open strSQL,&quot;PROVIDER=MSIDXS;DATA SOURCE=&quot; & strDataSource

' Are there any records to show? If objRS.EOF Then

' Show a default message if nothing is found. Response.Write &quot;No Documents were Found.&quot; & vbCrLf

' Otherwise... Else

' Start a table. Response.Write &quot; &quot; & vbCrLf End If

Else ' User has not entered any value in search form Response.Write &quot;Please enter a Search Term before submitting the form&quot; & vbCrLf End if%>  On the File menu, click Save.

Step 4: Test the sample ASP page

 * 1) Start SharePoint Designer 2007, 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.
 * 4) In the list, click the field that you want to query.
 * 5) Click Submit.
 * 6) Any results that match your query appear in a table on the page.

Step 5: Customize the sample ASP page
The two customization options are as follows:
 * Change the catalog
 * Modify the Field list

Change the catalog
If multiple Index Server catalogs are defined on the Web server, you can specify that the sample page use a different catalog. To do this, follow these steps:  Start SharePoint Designer 2007, and then open the sample Web page that you created earlier. Click Code to switch to HTML view.</li>  Locate the following line of code. Const strDataSource = &quot;WEB&quot; </li>  Change the value of strDataSource to the name of your catalog so that the code resembles the following code: Const strDataSource = My_Custom_Catalog </li> On the File menu, click Save, and then close the file.</li></ol>

Modify the &quot;Field&quot; list
 Start SharePoint Designer 2007, and then open the sample Web page that you created earlier.</li> Click Code to switch to HTML view.</li>  Locate the line of code that resembles the following code. Const strDisplayFields = &quot;Rank, DocAuthor, DocAppName&quot; </li>  Change the list of values. Separate each field name with a comma so that the line resembles the following line: Const strDisplayFields = &quot;Rank, DocAuthor, DocAppName, DocTitle&quot; </li> On the File menu, click Save, and then close the file.</li></ol>

The following table lists the values that you can use for the strDisplayFields variable.

Troubleshooting
<ul> 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 issue, start the Index Service.</li> If you specify a catalog that is not valid, you receive an error message that 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 issue, check the value of the strDataSource variable. If the value is correct, restart the Index Service.</li></ul>

<div class="references_section">