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'm working with some custom search scopes, and adding them to a Scope Display Group. I'm wondering if it's possible to programmatically change the order within a display group, depending which site is being viewed.

For example: Let's say my site has 4 areas

Marketing: US
Marketing: French
Support: Version 1
Support: Version 2

I've created custom scopes for each, using the names above. I also added them to a Scope Display Group in the order above.

Now let's say I'm viewing the Support: Version 1 site of my site collection. What I'd like to see is:

Support: Version 1
Support: Version 2
Marketing: US
Marketing: French

Or, say, I'm in the French site of the site collection. I'd like to see this:

Marketing: French
Marketing: US
Support: Version 1
Support: Version 2

Anyone know if this is possible?

I'm expecting that a Visual Studio based solution may be the only way, which is fine. I think I'd just need a nudge in the right direction to be able to locate the display group and change the order in a User Control.

share|improve this question
up vote 3 down vote accepted

You can solve your problem in various ways:

  1. Change per sitecollection the order of the scopes in the displaygroup that you are using
  2. Add 2 site collection type displaygroups, either one with the correct order. Create the displaygroups in a feature, with the correct order of scopes in that group, and use the correct displaygroup for your searchbox.

the code you could use as example is:

SPSite site = SPContext.Current.Site;
RemoteScopes remoteScopes = new RemoteScopes(SPServiceContext.GetContext(site));
var displayGroups = remoteScopes.GetDisplayGroupsForSite(new Uri(site.Url));
var displayGroup = SelectDisplayGroup(displayGroups);  // select correct displaygroup

// insert logic to add/remove scopes, to put the scopes in the correct order
displayGroup.RemoveAt(i) // displayGroup.Remove(scope)
displayGroup.Insert(i, scope)

the object model doesn't support moving scopes around besides the explicit removal and addition of scopes. (as far as i know ;))

share|improve this answer
Thanks, @Bas-Lijten - I think that's just the information I needed. I've done some work with RemoteScopes before but not spotted the GetDisplayGroupsForSite method. I should be able to take this info and produce just what I need :) – QMKevin Feb 22 '12 at 13:12
make sure to cast the objects within the IEnumerable that is returned to the ScopeDisplayGroup, otherwise, you won't be able to remove or insert the items – Bas Lijten Feb 22 '12 at 13:23

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.