Wednesday, February 11, 2009

Programmatically Disabling Search in Sharepoint

To disable search in one sharepoint Website

SPWeb spWeb = new SPSite("http://krishna/sites/rama").AllWebs["Narayana"];
spWeb.AllowAutomaticASPXPageIndexing = false;
spWeb.ASPXPageIndexMode = WebASPXPageIndexMode.Never;
spWeb.NoCrawl = true;

To disable Search for all the Web sites in the given site collection in Sharepoint.

foreach (SPWeb web in new SPSite("http://krishna/sites/rama").AllWebs)
web.AllowAutomaticASPXPageIndexing = false;
web.ASPXPageIndexMode = WebASPXPageIndexMode.Never;
web.NoCrawl = true;

This code will not disable the search box, but, gives zero results for any search query.

No comments:

Post a Comment