2008-05-26

Customizing the sharepoint search control


There are a couple ways of doing this.

  1. Modify ..\12\TEMPLATE\FEATURES\ContentLightup\Controls\searchArea.xml

  2. Modify ..\12\TEMPLATE\CONTROLTEMPLATES\searcharea.ascx

  3. Create a new feature and control

  4. Create a new feature that changes parameters for "SmallSearchInputBox"


I believe option 4 to be the best as it uses Microsoft.SharePoint.PortalWebControls.SearchBoxEx class and you don't need to create a new control.

There are a large number of properties you can use to customize the control and you should find the one you're looking for
microsoft.sharepoint.portal.webcontrols.searchboxex_properties.


So how do we customize it?
Create a new feature.


  1. Create a new directory anywhere eg: C:\RPSearchFeature

  2. Create a new manifest.xml in C:\RPSearchFeature with the following:
    <?xml version="1.0" encoding="utf-8"?>
    <Solution
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd=
    "http://www.w3.org/2001/XMLSchema"
    SolutionId=
    "GENERATE_A_GUID"
    ResetWebServer=
    "True"
    xmlns=
    "http://schemas.microsoft.com/sharepoint/">

    <FeatureManifests>
    <FeatureManifest Location="PortalSearch\feature.xml" />
    </FeatureManifests>
    </Solution>


  3. Create "C:\RPSearchFeature\PortalSearch\feature.xml" with:
    <?xml version="1.0" encoding="utf-8"?>
    <Feature Id="7095f774-1efa-4879-b074-ff211f5559c7"
    Title="Small Portal Search"
    Description="Smaller search bar without scopes"
    Version="12.0.0.0"
    Hidden="FALSE"
    Scope="Web"
    DefaultResourceFile="core"
    xmlns="http://schemas.microsoft.com/sharepoint/">

    <ElementManifests>
    <ElementManifest Location="elements.xml"/>
    </ElementManifests>
    </Feature>


  4. Create "C:\RPSearchFeature\PortalSearch\elements.xml" with:
    <?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="SearchResultPageURL">/search/results.aspx</Property>
    <Property Name="FrameType">None</Property>
    <Property Name="DropDownMode">HideDD_NoScope</Property>
    <Property Name="TextBoxWidth">140</Property>
    <Property Name="ShowAdvancedSearch">false</Property>
    </Control>
    </Elements>



  5. Wrap the feature up in to a solution "SearchFeature.wsp" with cabpack


  6. Deploy the solution.


  7. Enable the feature (Scope is web, but you can change it to site if that suits you).


The instruction that will enable these parameters over the default is the sequence number. The default sequence is 99, so anything below 99 will load first. The parameters I'm using set the "SearchResultPageURL", hide the scope drop down and remove the advance search link.


11 comments :

  1. I'd like to try your solution, however I do not understand these steps (never packaged up my own webpart or other customisation):

    * Wrap the feature up in to a solution "SearchFeature.wsp" with cabpack

    * Deploy the solution.


    Any chance you could step by step go through this part ?

    ReplyDelete
  2. These are xml files (a feature) that you need to add to sharepoint. You can manually copy the xml files to your SP feature directory or you can package them in a solution file, which is just a CAB with a wsp extension.

    Google: feature + solution

    ReplyDelete
  3. Well I have the custom feature activated and showing in my site features list. I have a search box displaying on all pages which seams to at least be applying the removed scope and advanced link, but all other properties I have are being ignored in the elements.xls file.

    That is, the text box width, dropdownbox width, etc. To test if it is recognising the custom properties or the original I turned the advanced link back on. That is still hidden ???? So I'm really confused ... is it possible the master template is recognising a prior version of the custom feature and not the most recent.

    Do I need to do anything (I tried deactivate and activate again) after changes to the xml files to ensure the feature is using those new changes ? I just copy the file back into the respective /features/searchfeature folder directly.

    I really appreciate your help on this.

    Anita

    ReplyDelete
  4. Read: http://msdn.microsoft.com/en-us/library/ms470880.aspx

    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.portal.webcontrols.searchboxex.aspx

    ReplyDelete
  5. Thank you Ray for your patience.

    ReplyDelete
  6. Hi Ray,
    Thanks for the help it works.

    Shashank

    ReplyDelete
  7. Hi Ray,
    Thanks for the help it works.

    Shashank

    ReplyDelete
  8. Hi Ray,
    Thanks for the help it works.

    Shashank

    ReplyDelete
  9. Ray,

    I am trying to implement a custom small search box in order to just redirect the contextual scopes result page like you have. Since this is for a MOSS Enterprise publishing Portal, do I start the OSearchEnhanced, OSearchBasic or ContentLightUp as it appears you have? The main difference I see is that the later references DefaultResourceFile="core" and the first two ref DefaultResourceFile="spscore".

    Your suggestions would be appreciated.

    ReplyDelete
  10. DefaultResourceFile, just specifies the resource file to use... I'm not using any resource parameters so it probably isn't even required.

    You've lost me with the OSearchEnhanced... this feature uses an existing MS control with different properties.

    ReplyDelete
  11. Once you join model new} account, you’ll have access to a $3,000 crypto welcome bonus. If you like fiat playing, the welcome bonus is a bit decrease - a $2,000 welcome package. What are the choices you have have} phrases of|in relation to} making deposits and withdrawals? For most on-line casinos, deposits are speedy for apparent causes. As for the second question concerning the security of on-line playing, on-line playing is, actually, secure. However, and as you'll be able to|you presumably can} think about, there will 빅카지노 at all times be risks, especially whenever you gamble with shady websites.

    ReplyDelete