Archive

Archive for the ‘Branding’ Category

Customizing the search box using a feature

October 14, 2010 2 comments

Lets see how we can modify the search box size in SharePoint 2010 using a custom feature.

The search control can be easily customized using the delegate control. When we open the master page we see something similar to this

<SharePoint:DelegateControl ID=”DelegateControl1″

                                                             runat=”server”

                                                            ControlId=”SmallSearchInputBox”

                                                           Version=”4″/>

As you can see the Id is SmallSearchInputBox. We take this ID and add custom properties, overriding the default ones.

Lets get started with the feature creation.

<?xml version=”1.0″ encoding=”utf-8″ ?>
<Feature  Id=”{266A0BF3-CFA3-46B7-E78E-8EA27A012BA5}”
          Title=”Custom Search Area”
          Description=”Change the default properties of the search control”
          Scope=”Site”
          xmlns=”http://schemas.microsoft.com/sharepoint/“>

    <ElementManifests>
        <ElementManifest Location=”searchproperties.xml”/>
    </ElementManifests>

</Feature>

Now create the Elements.xml in this case the searchproperties.xml.

<?xml version=”1.0″ encoding=”utf-8″ ?>
<Elements xmlns=”http://schemas.microsoft.com/sharepoint/“>
 <Control
        Id=”SmallSearchInputBox”
        Sequence=”10″
        ControlClass=”Microsoft.SharePoint.Portal.WebControls.SearchBoxEx” ControlAssembly=”Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”>
  <Property Name=”TextBoxWidth”>250</Property>
  <Property Name=”GoImageUrl”>/_layouts/images/gosearch.gif</Property>
  <Property Name=”GoImageUrlRTL”>/_layouts/images/goRTL.gif</Property>
  <Property Name=”GoImageActiveUrl”>/_layouts/images/gosearch.gif</Property>
  <Property Name=”GoImageActiveUrlRTL”>/_layouts/images/goRTL.gif</Property>
  <Property Name=”UseSiteDefaults”>true</Property>
  <Property Name=”FrameType”>None</Property>
  <Property Name=”ShowAdvancedSearch”>false</Property>
  <Property Name=”DropDownMode”>ShowDD_DefaultContextual</Property>
  <Property Name=”ScopeDisplayGroupName” />
 </Control>
</Elements>

As we can see, there are a number of properties that are being overridden to achieve the variation.