SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a question regarding the search scopes on sharepoint 2007.

I want to create a feature that will be activated on a web scope. If the feature is activated on that site and in all document libraries, etc the contexctual search should be activated instead of standard "all sites".

So how can i do it programmatically? Setting conextual search scope (ex: this list: name of the list) selected?

Thanks in advance

share|improve this question

First of all you need to set the search center url:

        using (SPSite site = web.Site)
            using (SPWeb rootWeb = site.RootWeb)
                rootWeb.AllProperties["SRCH_ENH_FTR_URL"] = "/Search/Pages";

Next you can remove the all sites search scope from the search dropdown grouping:

    public void UpdateSearchScopes(SPWeb web)
        SearchContext context;
        using (SPSite site = web.Site)
            context = SearchContext.GetContext(site);
        Scopes scopes = new Scopes(context);
        ScopeDisplayGroup group = scopes.GetDisplayGroup(new Uri(web.Url), "Search Dropdown");

            Scope all = scopes.GetSharedScope("All Sites");
            if (group.Contains(all) == true)
        catch { }

share|improve this answer
Hmm, but I don't want to delete the scopes. I just want to select the contextual search scope as default only if the feature is activated on the site (not site col) – Shkipper Jun 6 '12 at 14:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.