Monday, January 30, 2012

Enable Content Search on SharePoint 2010 My Site Top Navigation Bar

On SharePoint 2010 My Site top navigation bar, users can only do people search out of box. The OOTB My Site top navigation bar looks like:


I found out it’s actually not hard to enable content search on the top navigation bar. After adding a feature to My Site web application, the My Site top navigation bar will look like:



or




Now we can search content in All Sites scope and search people in People scope.

So how to make it happen exactly? The answer is delegate control. Delegate controls act like container controls which encapsulate default content (set of child controls inside it). The default content (set of child controls associated with delegate) can be substituted by specific controls through features. The ability to override or substitute the delegate controls brings the power & flexibility to brand SharePoint 2010 Sites.

The OOTB SharePoint Foundation marster pages define My Site top navigation bar as a delegate control with id "GlobalNavigation". We just need to create a new control and subsitute the default control with a smaller sequence number.

Let's create an empty SharePoint project deploying as a farm solution, and add a SharePoint Mapped Folder which maps to new sub folder of controltemplates folder in 14 hive. Under the new folder, we create our new control based on the default control MySiteTopNavigation.ascx under $14hive\templates\controltemplates.

We can copy MySiteTopNavigation.ascx from 14 hive controltemplates to the new mapped folder, Then swap





with










Next, add CSS style to do some makeup inside the new MySiteTopNavigation.ascx.













Next, add a empty element called "MySiteSearchDelegate", and put the following content into the Elements.xml file.








Finnally, add a feature with web application scope to deploy the element. The structure of this project would like someting like:
















After deploying the generated solution pack, and activating the feature in My Site web application, the new top navigation bar will show up....

1 comment: