Click here to Skip to main content
15,561,907 members
Articles / Web Development / IIS
Article
Posted 25 Jul 2004

Stats

239.4K views
1.6K downloads
43 bookmarked

Microsoft Content Management Server Search Controls (C#)

Rate me:
Please Sign up or sign in to vote.
4.47/5 (9 votes)
27 Jun 2005CPOL3 min read
Gives Content Management Server web sites search capability using SharePoint Portal Server as the search engine.

Sample Image - sample.gif

Introduction

This set of user controls gives Microsoft Content Management Server (MCMS) web sites search capability using SharePoint Portal Server (SPS) as the search engine. It uses SPS' Search web service to provide a simple key word search. A search option is provided to select specific Content Index. The search results are displayed in a customizable DataGrid.

A VB.NET version of this set of user controls is available here.

SharePoint Setup

Please reference Emmanuel Desigaud's article on how to set up SPS for search. Basically, you need to set up a Content Index and add a Content Source. Also, make sure users performing searches in your CMS site have access to the SPS Search web service.

Installation

  1. Copy SPSSearch.xml to your XML directory if you have one, or any location in your web site. If you like to include additional columns in your search results, add the additional fields to the select statement. You can also change the maximum number of search results returned, in <Count>500</Count>, if so desired.
  2. Copy user control SearchInput to your user controls directory. The default search button is a text button. If you like an image button instead, change the Visible attribute of SearchButton and SearchImageButton accordingly and update the ImageUrl of the SearchImageButton. Do not delete either button even if you are not using both.
  3. Copy user control SearchResults to your user controls directory. If you have added additional fields in SPSSearch.xml, customize SearchResult.ascx to include those fields. In SearchResults.aspx.cs, qualify namespace SPSSearch in line 18: using ProjectName.SPSSearch; with your project name.
  4. Copy QueryService.cs and SearchUtilities.cs to your class directory.
  5. Copy Search.css to your CSS directory.
  6. In your web.config, add the following keys to the appSettings:
    XML
    <appSettings>
        <add key="QuestechSystems.SPSSearchUrl" 
          value="http://<SPSServer>/_vti_bin/search.asmx" />
        <add key="QuestechSystems.SPSSearchXml" value="[Url to SPSSearch.xml]" />
        <add key="QuestechSystems.SPSSearchIndexesText" 
          value="[A comma delimited list of Content Indexes Display Name]" />
        <add key="QuestechSystems.SPSSearchIndexesValue" 
          value="[A comma delimited list of Content Indexes]" />
    </appSettings>

    For example:

    XML
    <appSettings>
        <add key="QuestechSystems.SPSSearchUrl" 
          value="http://<SPSServer>/_vti_bin/search.asmx" />
        <add key="QuestechSystems.SPSSearchXml" 
          value="/<CMS Site Application Name>/Xml/SPSSearch.xml" />
        <add key="QuestechSystems.SPSSearchIndexesText" 
          value="All,Sub Site 1,Sub Site 2" />
        <add key="QuestechSystems.SPSSearchIndexesValue" 
          value="All,Sub_Site_1_Content_Index,Sub_Site_2_Content_Index" />
    </appSettings>

    A drop down list for the Content Indexes specified will be added in the SearchInput user control. The "All" in SPSSearchIndexesValue is a special value that defines search to be performed on all Content Indexes defined in SPSSearchIndexesValue. If you only have one Content Index to search, add the following instead:

    XML
    <appSettings>
        <add key="QuestechSystems.SPSSearchUrl" 
          value="http://<SPSServer>/_vti_bin/search.asmx" />
        <add key="QuestechSystems.SPSSearchXml" 
          value="/<CMS Site Application Name>/Xml/SPSSearch.xml" />
        <add key="QuestechSystems.SPSSearchIndexesValue" 
          value="Site_Content_Index" />
    </appSettings>

    No drop down list will be added for this case.

  7. Add user control SearchInput to your CMS site to where you want the search input box to show. The results page URL is specified via the SearchResultsUrl property. The search results page can be a CMS template page or a regular ASP.NET page. For example:
    ASP.NET
    <%@ Register TagPrefix="uc1" 
        TagName="SearchInput" Src="~/UserControls/SearchInput.ascx" %>
    . . . . . .
    <uc1:SearchInput id="SearchInput" 
        SearchResultsUrl="" DefaultSearchIndex="" runat="server">
    </uc1:SearchInput>

    If SearchResultsUrl is not specified, the current page will be used for the results page. If you have specified multiple Content Indexes, you can select the default Content Index to search using the DefaultSearchIndex property. Customize SearchInput.ascx to change the layout of the search input elements.

  8. Add user control SearchResult to your search results page. The control has two properties you can set:
    • DefaultPageSize: The number of search results per page. Default is 10.
    • FilterRights: [true|false]. By default, the search results will filter out any CMS page that you don't have access to see. If your search results do not contain any authorized content and/or if you would like to improve performance, set it to false. Use it with caution though.
  9. Include Search.css to all pages that reference the search controls.
  10. Include all new files to your CMS project. Rebuild your site in VS.NET.

Notes

  1. If SearchResults encounters any errors, it will mask the errors and return "No pages were found". To see the actual errors, add querystring "debug=true" to the search results page and reload the page.
  2. The search controls run in CMS Unpublished mode. The links returned in the search results are all published links, however.

History

  • V1.0 - 2004.07.26 - Base.
  • V1.1 - 2004.08.20 - Enabled search for meta Keywords and Description.
  • V1.2 - 2005.02.05 - Added option to search multiple Content Indexes.
  • V1.3 - 2005.02.13 - Added configurable SPS Search Web Service URL in web.config to facilitate deployment. (Please note: all Web.Config App Settings key names are now qualified with namespace.)
  • V1.4 - 2005.06.25 - Allows exact phrase search.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Canada Canada
A Microsoft Certified Professional Developer and Technology Specialist.

Experience and expertise in SharePoint 2016 / 2013 / 2010 / 2007.

Role ranges from a developer in a multi-person team to a solution consultant with expert-level skills, leading a project to completion status.

Proven experience working effectively in a team environment and a self-managed environment.

Comments and Discussions

 
GeneralSharepoint portal Pin
Prakash A 19804-Oct-07 22:41
Prakash A 19804-Oct-07 22:41 
GeneralUserHasRightToBrowse syntax Pin
Viracboy28-Jun-06 13:00
Viracboy28-Jun-06 13:00 
GeneralDefault web.config settings Pin
James Coleman26-Apr-06 12:42
James Coleman26-Apr-06 12:42 
GeneralRe: Default web.config settings Pin
Stephen Huen30-Apr-06 18:41
Stephen Huen30-Apr-06 18:41 
GeneralThe Local Security Authority cannot be contacted Pin
Jeff Tsang18-Oct-05 12:27
Jeff Tsang18-Oct-05 12:27 
GeneralRe: The Local Security Authority cannot be contacted Pin
Stephen Huen18-Oct-05 14:58
Stephen Huen18-Oct-05 14:58 
GeneralInternal Server Error Pin
Jeff Rush14-Oct-05 11:05
Jeff Rush14-Oct-05 11:05 
GeneralRe: Internal Server Error Pin
Jeff Rush14-Oct-05 11:29
Jeff Rush14-Oct-05 11:29 
GeneralRe: Internal Server Error Pin
Stephen Huen18-Oct-05 15:23
Stephen Huen18-Oct-05 15:23 
QuestionRe: Internal Server Error Pin
James Coleman17-Apr-06 12:07
James Coleman17-Apr-06 12:07 
AnswerRe: Internal Server Error Pin
James Coleman17-Apr-06 12:32
James Coleman17-Apr-06 12:32 
GeneralRe: Internal Server Error Pin
Stephen Huen17-Apr-06 15:18
Stephen Huen17-Apr-06 15:18 
GeneralRe: Internal Server Error Pin
James Coleman17-Apr-06 16:32
James Coleman17-Apr-06 16:32 
GeneralRe: Internal Server Error Pin
Stephen Huen18-Apr-06 15:16
Stephen Huen18-Apr-06 15:16 
Generalpublic folders on exchange Pin
Viracboy11-Jul-05 11:39
Viracboy11-Jul-05 11:39 
GeneralRe: public folders on exchange Pin
Stephen Huen11-Jul-05 16:56
Stephen Huen11-Jul-05 16:56 
GeneralRe: public folders on exchange Pin
Viracboy12-Jul-05 7:03
Viracboy12-Jul-05 7:03 
GeneralRe: public folders on exchange Pin
Stephen Huen18-Jul-05 18:46
Stephen Huen18-Jul-05 18:46 
GeneralUsing basic authentication Pin
Viracboy6-Jul-05 13:17
Viracboy6-Jul-05 13:17 
GeneralRe: Using basic authentication Pin
Stephen Huen6-Jul-05 20:49
Stephen Huen6-Jul-05 20:49 
GeneralRe: Using basic authentication Pin
Viracboy11-Jul-05 10:22
Viracboy11-Jul-05 10:22 
GeneralRe: Using basic authentication Pin
Viracboy11-Jul-05 10:25
Viracboy11-Jul-05 10:25 
GeneralRe: Using basic authentication Pin
Viracboy11-Jul-05 10:57
Viracboy11-Jul-05 10:57 
GeneralRe: Using basic authentication Pin
Stephen Huen11-Jul-05 16:59
Stephen Huen11-Jul-05 16:59 
GeneralRe: Using basic authentication Pin
jamesy blair26-Feb-07 5:56
jamesy blair26-Feb-07 5:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.