Allen的自由天空

有财富未必有人生,有人生未必有财富

导航

Modifying the SharePoint Search control(转载)

Modifying the SharePoint Search control

Anyone who has used SharePoint will be familiar with the search control which is on most pages, and gives user's the option to search on various scopes within the portal, and will direct the user to the search centre when performing a search. In SharePoint 2007, developers are probably less familiar with how to modify the appearance of this control - but it really isn't too hard at all as it's appearance and functionality is controlled by some simple XML.

Located in the hive in the features folder (default: C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\OSearchBasicFeature and OSearchEnhancedFeature) is an xml file called SearchArea.xml. By modifying the contents of this file you are able to change immediately and consistantly the appearance of the search box control within SharePoint.

There are several different properties which you can use to define this, and for the full list it is worth checking out the control definition at Microsoft. I am going to highlight a few of note though, which I think are most useful.

The property DropDownMode defines how the dropdown box should be displayed. ShowDD displays the dropdown with all scopes. HideDD_useDefaultScope displays no dropdown, however will search on the default scope for the page. For a list of all possible values there is a list located here.

For styling there is some great properties like DropDownWidth for defining the width of the dropdown, TextBoxWidth for the width of the search box and SearchBoxTableClass which defines the style class for the table that the search box will be wrapped in. The property TextBeforeDropDown is a property which allows you to add text which appears to the left of the dropdown, while TextBeforeTextBox displays the text to the left of the search box itself. ShowAdvancedSearch is a simple boolean to define whether or not the advanced search is available, while AdvancedSearchPageURL is the link that the Advanced Search link should point to.

Here is a sample implementation of a search control:

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="
http://schemas.microsoft.com/sharepoint/">
<Control
Id="SmallSearchInputBox"
Sequence="25"
ControlClass="Microsoft.SharePoint.Portal.WebControls.SearchBoxEx" ControlAssembly="Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">
<Property Name="DropDownMode">ShowDD</Property>
<Property Name="SearchResultPageURL">/_layouts/osssearchresults.aspx</Property>
<Property Name="FrameType">None</Property>
<Property Name="DropDownWidth">140</Property>
<Property Name="TextBoxWidth">140</Property>
<Property Name="ShowAdvancedSearch">true</Property>
<Property Name="TextBeforeDropDown">Search</Property>
<Property Name="AdvancedSearchPageURL">
http://MySite/SearchCenter/Pages/AdvancedResults.aspx</Property>
</Control>

This control is then simply added into the master page by using a delegate control.

<SharePoint:DelegateControl ID="DelegateControlSearchExclude" runat="server" ControlId="SmallSearchInputBox"/>

The ControlId in this control matches the Id of the control in the XML. You can add multiple control definitions in the XML, provided each has it's own unique Id. The appropriate control can then be displayed within the masterpage by referencing the correct control.

posted on 2007-10-17 16:42  AllenFeng  阅读(527)  评论(0编辑  收藏  举报