Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

1 Answer 1

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";
                rootWeb.Update();
            }
        }

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");

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

        group.Update();
    }
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

 
discard

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.