Click here to Skip to main content
Click here to Skip to main content

Search User Controls for Microsoft Office SharePoint Server (MOSS)

, 29 Aug 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
A set of user controls to provide Microsoft Office SharePoint Server (MOSS) search functionality
Screenshot - sample.gif


Although the out-of-the-box search Web parts provided by Microsoft Office SharePoint Server (MOSS) 2007 are very customizable, there are situations where you may want to develop your search interface to hook into MOSS. This download consists of a Search Box user control and a Search Results user control. The Search Results user control uses the new FullTextSqlQuery API to return the search results. As user controls (I might add a Web part version later), the look and feel are very easy to customize.


The Search Box user control SearchBox.ascx has several public properties:

  • SearchResultsUrl - URL of the search results page. Default is the current page.
  • DefaultSearchScope - Default search scope. Default is All Sites.
  • SearchScopes - A comma delimited list of search scopes. If provided, they will be rendered in a dropdown list for user to limit the scope of the search.

The Search Results user control SearchResults.ascx has several public properties:

  • ResultFields - A comma delimited list of result fields. Default is WorkId, Rank, Title, Author, Size, Path, Description, Write, SiteName, CollapsingStatus, HitHighlightedSummary, HitHighlightedProperties, ContentClass, IsDocument, PictureThumbnailURL.
  • RowLimit - The number of search result items returned per page. Default is 10.
  • HitHighlightedTag - The HTML tag (without the enclosing angled brackets) to highlight the search words when rendering the result field HitHighlightedSummary. Default is b for bold.


The sample Visual Studio 2005 SP1 solution includes all the support files you need to build and deploy the user controls, minus strong name key files (*.snk). (The supplied Visual Studio 2005 solution contains Web Application projects supported only by SP1 or after.) It contains two projects: Deployment and Office.Server.Search. The Office.Server.Search project contains source codes for the user controls. The Deployment project contains a pre-build script to aggregate all the files needed for deployment. It contains a Solution directory where a WSP file is generated and deployed by a post-build script.

This structure of Visual Studio solution and projects is designed to be scalable to full blown MOSS/WSS development and deployment. You could add additional projects like SharePoint for WSS/MOSS development or SharePoint.Publishing for MOSS Publishing development. Within your projects, you could have other custom components like Web controls, Web parts, custom fields, feature receivers etc.

Of course you can install the user controls as is without further customization. Using stsadm, install the solution file QuestechSolution.wsp in \Deployments\Solution\:

stsadm -o addsolution -filename QuestechSolution.wsp

Then go to SharePoint Central Administration/Operations/Global Configuration-Solution Management and deploy the solution to selected Web applications. To insert the user controls to a page, modify the appropriate master page or page layout as follows:

<%@ Register TagPrefix="Questech" TagName="SearchBox"
      src="~/_controltemplates/Questech/SearchBox.ascx" %>

<%@ Register TagPrefix="Questech" TagName="SearchResults"
      src="~/_controltemplates/Questech/SearchResults.ascx" %>
<Questech:SearchBox id="SearchBox" runat="server" />

<Questech:SearchResults id="SearchResults" runat="server" />


  1. Enterprise Search Query Object Model Overview
  2. Custom Enterprise Search Web Part Code
  3. Creating a Web part to explicitly search custom columns in MOSS 2007 - Part 1 and 2
  4. MOSS - Search Scopes


  • V1.2 - 2008.08.26 - Added support for sites run under extended web applications
  • V1.1 - 2008.04.22
    • Included sample Visual Studio 2005 solution for compiling and deploying the user controls
    • Updated installation instructions
  • V1.0 - 2007.03.22 - Base


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


About the Author

Stephen Huen
Software Developer (Senior)
Canada Canada
A Microsoft Certified Professional Developer and Technology Specialist.

Experience and expertise in SharePoint 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.
Follow on   LinkedIn

Comments and Discussions

QuestionIts not working Pinmemberkarthikmandadi@gmail.com25-Jul-12 21:50 
GeneralCustom search in WSS 3.0 Pinmembersmasher91-Aug-09 18:16 
Questionproblem with PATH property in extended site Pinmemberbilalfastian25-Aug-08 11:14 
AnswerRe: problem with PATH property in extended site PinmemberStephen Huen26-Aug-08 10:28 
QuestionHow to set Public Properties PinmemberBharat Chopra28-Apr-08 6:03 
AnswerRe: How to set Public Properties PinmemberStephen Huen29-Apr-08 17:22 
GeneralHitHighLightedSummary PinmemberSearchDeveloper29-Jan-08 5:24 
Generalows_name(Text) PinmemberSearchDeveloper15-Jan-08 9:15 
GeneralSearch PinmemberSearchDeveloper12-Dec-07 5:30 
GeneralScopes PinmemberSearchDeveloper4-Dec-07 5:44 
Hi ,

I wrote this function to create scopes and calling on the page load of SearchBox.ascx.
Am i doing the correct thing. By doing this will i be able to hook up the custom scope or is it required tio activate it thru feature. Iam not able to open my page of site if i include this function in the dll. I dont know what went wrong. Please help me

protected void CreateSearchScopes()

serverctx = ServerContext.GetContext("SharedServicesDevNew");
searchctx = SearchContext.GetContext(SPContext.Current.Site);
Scopes scopes = new Scopes(searchctx);
Scope newScope = null;

//Scope Array for Scope Identification
string[] ScopeArray = { "Diseases/Conditions", "Services", "Doctors", "News", "Events/Classes", "Healthy Living", "Education", "Research", "Publications" };

//Folder Array for Rules Creation
string[] folder = { "disorders", "services", "physicians", "news", "events", "classes", "healthy_living", "education", "research", "publications", "newsletters" };

for (int Scope_Index = 0, Rule_Index = 0; Scope_Index < ScopeArray.Length; Scope_Index++, Rule_Index++)
//Create a New Scope
newScope = scopes.AllScopes.Create(ScopeArray[Scope_Index], string.Empty, null, true, "http://dev/Pages/SearchTest.aspx", ScopeCompilationType.AlwaysCompile);

//For The Created Scope Create a New Rule Based on Folder(Rule) Array Data
//Check Whether the Index is in the Limit Before Accessing the Array. Otherwise it Asserts.
if (Rule_Index < folder.Length)
newScope.Rules.CreateUrlRule(ScopeRuleFilterBehavior.Include, UrlScopeRuleType.Folder, folder[Rule_Index]);

//If Scope is Events/Classes or Publication we have to add two Rules.
if ((Scope_Index == 4) || (Scope_Index == 8))
//So Increment the Rule Array Index by One
//So Folder Array Points to Classes if Scope is Events/Classes or newsletters if Scope is Publications
//Check Whether the Index is in the Limit Before Accessing the Array. Otherwise it Asserts.
if (Rule_Index < folder.Length)
//Access the Next Array Element and Create the Rule
newScope.Rules.CreateUrlRule(ScopeRuleFilterBehavior.Include, UrlScopeRuleType.Folder, folder[Rule_Index]);


//It will compile all the scopes and updates them
ScopeDisplayGroup group = scopes.GetDisplayGroup(
(new Uri(SPContext.Current.Site.Url)),
"search dropdown");

GeneralHelp in Search PinmemberSearchDeveloper29-Nov-07 11:43 
GeneralRe: Help in Search PinmemberStephen Huen29-Nov-07 15:00 
GeneralRe: Help in Search PinmemberSearchDeveloper30-Nov-07 12:34 
GeneralRegarding PictureThumbNailURL PinmemberSearchDeveloper28-Nov-07 10:28 
GeneralRe: Regarding PictureThumbNailURL PinmemberStephen Huen28-Nov-07 12:40 
QuestionQuestion on Search PinmemberVvenkatesan28-Nov-07 4:51 
AnswerRe: Question on Search PinmemberStephen Huen28-Nov-07 11:36 
GeneralRe: Question on Search PinmemberVvenkatesan28-Nov-07 11:38 
GeneralRegarding Scope PinmemberSearchDeveloper27-Nov-07 7:05 
GeneralRe: Regarding Scope PinmemberStephen Huen27-Nov-07 9:41 
GeneralAdvance Search PinmemberVvenkatesan26-Nov-07 9:55 
Generalwebpart for custom search using keyword query class(creating a search restriction) Pinmembershareknk20-Nov-07 0:32 
GeneralRegarding Search PinmemberSearchDeveloper13-Nov-07 11:57 
GeneralRe: Regarding Search PinmemberStephen Huen13-Nov-07 22:34 
GeneralRe: Regarding Search PinmemberSearchDeveloper14-Nov-07 10:44 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150414.1 | Last Updated 29 Aug 2008
Article Copyright 2007 by Stephen Huen
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid