Pro-Tip: Change SharePoint Site Search Settings Programmatically

27 June 2011

If you need to change the Site Collection search settings (Such as the target search results page, or the dropdown properties), these settings are stored in the property bag for the web, not in an actual property of SPWeb.

The property mappings are:

  • SRCHENHFTR_URL – Search Center URL
  • SRCHSITEDROPDOWN_MODE – Search Scope Dropdown Type
  • SRCHTRAGETRESULTS_PAGE – Target Search Results page

So for example to set the target search result page to a page within the current web, you can do something like:

SPWeb web = SPContext.Current.Web;
web.AllProperties["SRC_TRAGET_RESULTS_PAGE"] = web.Url + "/Pages/Search.aspx";
web.Update();

You'll notice that I typed it out as SRCTRAGETRESULTS_PAGE...and it says traget, not target. That, is a real typo, in the API, and while it's obviously wrong, I doubt it will ever be fixed.

So the real lesson here is - make sure you spell stuff in your code correctly, or years from now someone will look at your names and laugh :)

Tags: search, SharePoint 2010, site settings

Add a Comment

No Comments