Programmatically updating the Search Settings for a Site Collection

So I had an interesting question come my way today.  We were looking for a way to programmatically update the values for the “Search Settings” which are found in the “Site Settings” of the site collection.  There is no API to do this and come to find out these values are stored as a part of the property bag of the SPWeb.  The three properties which represent the fields on the “Search Settings” page are as follows in the property bag:

"SRCH_ENH_FTR_URL" – Search Center URL

"SRCH_SITE_DROPDOWN_MODE" – Search Scope Drop down option

"SRCH_TRAGET_RESULTS_PAGE” – Target Search Results page


Sample Code to implement the custom settings

using (SPSite site = new SPSite("http://server/site"))

using (SPWeb web = site.OpenWeb())


web.AllProperties["SRCH_ENH_FTR_URL"] = "/sites/search/pages";

web.AllProperties["SRCH_SITE_DROPDOWN_MODE"] =    "HideScopeDD_DefaultContextual"       ;

web.AllProperties["SRCH_TRAGET_RESULTS_PAGE"] = "/sites/Search/Pages/Results.aspx";