SharePoint 2010: Create a Custom Search Box

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.

  1. 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:
    
    
    1
    C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14TEMPLATEFEATURESOSearchBasicFeature
  2. Create a new subdirectory in the FEATURES directory, in our case, we will name it OSearchBasicFeatureCustom, i.e.
    
    
    1
    C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14TEMPLATEFEATURESOSearchBasicFeatureCustom
  3. Copy all of the contents from the OSearchBasicFeature directory to the OSearchBasicFeatureCustom directory.
  4. 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.
  5. 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.
  6. 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:
    
    
    1
    HideDD_useDefaultScope

    Would you like to change the Search button? No problem, use:

    
    
    1
    /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:
    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.portal.webcontrols.searchboxex_properties.aspx

  7. 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.
  8. Run the following commands in the SharePoint 2010 Management Shell:
    
    
    1
    2
    Install-SPFeature OSearchBasicFeatureCustom
    Enable-SPFeature OSearchBasicFeatureCustom -Url <span class="green">http://www.yoursite.com/</span>

    Replace

    1
    http://www.yoursite.com

    with the actual url of your SP site.

  9. Even though the new feature is a farm feature, I sometimes got an error:
    
    
    1
    2
    3
    4
    5
    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 &gt;&gt;&gt;&gt;  OSearchBasicFeatureSPT -Url <span class="green">http://www.yoursite.com/</span>
    + CategoryInfo          : InvalidData: (Microsoft.Share...etEnableFeature: SPCmdletEnableFeature) [Enable-SPFeature], DuplicateNameException
    + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletEnableFeature
  10. My Suggestion to get around this is to disable, then re-enable the feature:
    
    
    1
    2
    Disable-SPFeature OSearchBasicFeatureSPT -Url <span class="green">http://www.yoursite.com/</span>
    Enable-SPFeature OSearchBasicFeatureSPT -Url <span class="green">http://www.yoursite.com/</span>
  11. The feature should now be ready to be used. Open your site, in our example
    1
    http://www.yoursite.com

    , in SPD.

  12. Open you masterpage, by default found in the /_catalogs/masterpage directory, named default.master.
  13. Edit the default.master file and look for the following code:
    1
    2
    3
    4
    5
    <div id="search-box">
        <asp:ContentPlaceHolder id="PlaceHolderSearchArea" runat="server">
            <SharePoint:DelegateControl</span> runat="server" ControlId="SmallSearchInputBox" Version="4"/>
        <asp:ContentPlaceHolder>
    </div>

    You only need to replace the ControlId property with the ID you set in the searcharea.xml file. In our example:

    1
    2
    3
    4
    5
    <div id="search-box">
       <asp:ContentPlaceHolder id="PlaceHolderSearchArea" runat="server">
          <SharePoint:DelegateControl runat="server" ControlId="SmallSearchInputBoxSPT" Version="4"/>
       <asp:ContentPlaceHolder>
    </div>
  14. Save, Check In and Publish as required. That’s it!

References

5 thoughts on “SharePoint 2010: Create a Custom Search Box

  1. […] SharePoint 2010: Create a Custom Search Box By Eric Overfield […]

  2. Peter March 22, 2012

    Hi Eric,
    at first thanks a lot for this post – it really works perfectly fine for me!
    I was wondering how i can add this feature to my VS-Solution since i have a solution where i manage my whole custom-masterpage and some images.
    The problem which i’m having is that im not quite sure how to integrate it to my solution. I tried to add it as a solution feature – which won’t work (maybe i just don’t get it) i also tried it by adding it as a new empty element, which also doesn’t work since we’re dealing with a feature and not an element 🙂
    Kind Regards,
    Peter

    1. Eric Overfield June 6, 2012

      Hi Peter,
      If you want to use the technique I provided in Visual Studio then either create a new feature, or you can use an existing feature, in your VS Project. If you already have an existing feature that applies your branding, then I suggest you just use that feature.
      Now, in your VS project, add a “new item”, in particular a “Blank Element”. Name it something like SmallSearchInputBoxSPT. This blank element will create a new Elements.xml file. This file will be / is the same as the, searcharea.xml file in the original example. In this Elements.xml file, replace what is there with what is found in the searcharea.xml. Make the changes I recommend in step 5 through step 6. Finally make sure that you include this elements.xml file in your feature.
      Thats it. You should now be able to reference the control in the delegate control using your new control id as set in Step 5.

  3. Clem September 8, 2012

    The oSearch directory does not exist in the 14 hive anywhere.

    1. Eric Overfield September 10, 2012

      Hi,
      The search feature should be found in the following directory, which is a part of the 14 hive. C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14TEMPLATEFEATURESoSearchBasicFeature. This feature might not be found in foundation only installations, it may only be a part of SharePoint 2010 Server. I will look this up and see if I can find out if this is or is not a feature including in Foundation. If you have SharePoint 2010 Server installed then I have no idea why you cannot find this feature unless an administrator removed it? That would be hard to believe though as I think it is needed OOTB.

Leave a Comment

Your email address will not be published. Required fields are marked *

Enter Code *

Filed Under

Related

Are you preparing to launch a new #SharePoint intranet?

Don’t spring it on employees out of the blue. First, talk to as many of them as you can.

Planning is just phase one. For all of our tips, watch our recent webinar!

http://ow.ly/dsQM50GqPI5

It's that time again! Join #Microsoft MVP & Regional Director, @EricOverfield on Thursday, October 28th, at 11:00 AM PST as he walks through #MicrosoftViva’s current state & offerings and what they mean to your #digitalworkspace right now.

http://ow.ly/3QFK50Gnx9f

It's the final countdown! Join @EricOverfield at 11am PST to learn about common pitfalls and paths to success when moving to #SharePointOnline. You'll walk away with practical tips to use in your organization today!

http://ow.ly/fdf150GjyJT

In today's episode of the #PixelMillWebinars, you'll learn from the experience of a global organization’s path to digital teamwork victory and get to see first-hand how to successfully plan a smooth migration for your team.

Join us at 11am PST!

https://pixelmill.com/webinar-9-takeaways-from-a-global-organizations-migration-to-sharepoint-online/

It's the day of the show y'all! Join #Microsoft RD +MVP @EricOverfield at 11am PST as we walk you through a multi-national enterprise software company’s migration journey to #SharePointOnline. Learn about common pitfalls and paths to success.

http://ow.ly/cN9250GjtGk

Subscribe to PixelMill's
E-news

* indicates required

Let's Talk Digital
Workspaces Today

Get In Touch