I came across this requirement, in which i need to configure the site collection level search settings programmatically, so that searching in a site collection will be redirected to custom search page in search center.
Here is what we need to do in case of settings the url via code.
//All URLs are for testing purpose only, please change according your needs
using (SPSite site = new SPSite("Your site url"))
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
web.AllProperties["SRCH_ENH_FTR_URL"] = "/sites/search/pages";
//For site collection level
web.AllProperties["SRCH_SB_SET_SITE"] = "{\"Inherit\":false,\"ResultsPageAddress\":\"/sites/Search/Pages/Results.aspx\",\"ShowNavigation\":false}";
//For subsite
web.AllProperties["SRCH_SB_SET_WEB"] = "{\"Inherit\":false,\"ResultsPageAddress\":\"/sites/Search/Pages/Results.aspx\",\"ShowNavigation\":false}";
web.Update();
web.AllowUnsafeUpdates = false;
}
}
In above code replace the highlighted relative url, to search results page url of your search center.
Once done given url will set as below.

No comments:
Post a Comment