0

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

1 Answer 1

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();
    }
1
  • 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
    Commented Jun 6, 2012 at 14:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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