sharepointsearchpropertiessitecollection

How do I programatically set the SharePoint's site collections Search Center property?


I have a site collection and I want to set the search center value to be the same as another site collection. The site collection is created in code, so I need to be able to set the property after the site collection has been created.

How can I do this programatically?


Solution

  • This setting is stored in the property bag of the SPWeb object. You can update it as follows:

    using (SPSite site = new SPSite("http://server/site"))
    using (SPWeb web = site.OpenWeb())
    {
      web.AllProperties["SRCH_ENH_FTR_URL"] = "/searchcenter/pages";
      web.Update();
    }