The SharePoint 2010 OOB basic seach box control can be slightly modified using CSS, but what if you want to make more changes that CSS just can’t do? No problem. The OOB Basic Search box is just a feature, so you all you need to do to copy the existing feature to a new custom feature, make your changes, install and activate it. Let’s see how this is done.
- You will want to find the existing OOB Basic Search feature. By default, that is found in the following location in your SharePoint 2010 server:
C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14TEMPLATEFEATURESOSearchBasicFeature
- Create a new subdirectory in the FEATURES directory, in our case, we will name it OSearchBasicFeatureCustom, i.e.
C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14TEMPLATEFEATURESOSearchBasicFeatureCustom
- Copy all of the contents from the OSearchBasicFeature directory to the OSearchBasicFeatureCustom directory.
- Open the feature.xml file found in the OSearchBasicFeatureCustom directory in a text editor and replace the GUID element with a new GUID. The quickest way to get a new GUID is to open Visual Studio and go to Tools->Create Guid.Also change the Title and Description elements while you are at it.
- Open the searchArea.xml file found in the OSearchBasicFeatureCustom directory in a text editor and change the ID element to a unqiue value like SmallSearchInputBoxCustom.
- Make other changes to the properties found in the searcharea.xml file. As an example, say that you would like to hide the scope. You would update the property:
Would you like to change the Search button? No problem, use:/Style Library/go.gif
Just change the url to match your search button.
For a reference all the different properties you can change, check out this list from Microsoft:
- Once you have made these changes and saved the xml files, it is now time to start the SharePoint 2010 Management Shell so you can install and enable the feature.
- Run the following commands in the SharePoint 2010 Management Shell:
Enable-SPFeature OSearchBasicFeatureCustom -Url <span class="green">http://www.yoursite.com/</span>
with the actual url of your SP site.
- Even though the new feature is a farm feature, I sometimes got an error:
Enable-SPFeature : Feature 'OSearchBasicFeatureSPT' (ID: 66a7a44f-c33d-48de-8a4 f-d60960849895) is already activated at scope '<span class="green">http://www.yoursite.com/</span>'.
At line:1 char:17
+ Enable-SPFeature >>>> OSearchBasicFeatureSPT -Url <span class="green">http://www.yoursite.com/</span>
+ CategoryInfo : InvalidData: (Microsoft.Share...etEnableFeature: SPCmdletEnableFeature) [Enable-SPFeature], DuplicateNameException
+ FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletEnableFeature
- My Suggestion to get around this is to disable, then re-enable the feature:
Disable-SPFeature OSearchBasicFeatureSPT -Url <span class="green">http://www.yoursite.com/</span>
Enable-SPFeature OSearchBasicFeatureSPT -Url <span class="green">http://www.yoursite.com/</span>
- The feature should now be ready to be used. Open your site, in our example
, in SPD.
- Open you masterpage, by default found in the /_catalogs/masterpage directory, named default.master.
- Edit the default.master file and look for the following code:
You only need to replace the ControlId property with the ID you set in the searcharea.xml file. In our example:
- Save, Check In and Publish as required. That’s it!
- Installing a feature: http://msdn.microsoft.com/en-us/library/ms442691.aspx
- SearchBoxEx properties: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.portal.webcontrols.searchboxex_properties.aspx
- Modifying the OOB Search Control in MOSS / SharePoint 2007: http://www.dotnetfunda.com/articles/article1056-customizing-oob-small-search-input-box-.aspx