Wednesday, November 3, 2010

Missing Set Up Groups page in SharePoint 2010

I discovered today that SharePoint 2010 gives you a nice new way to set the associated members group, but in doing so has hidden the "Set up Groups for this Site" page after initial site creation.

First the members group: This experience is actually much better. Most end users I have talked to are only concerned with which group is the default selection in the "Add users to a SharePoint group" dropdown on the "Add Users" page. A lot of them had trouble with the complexity of having to go to the "set up groups" page for this as it is definitely not the intuitive place to go. SharePoint 2010 has made this much easier. You simply navigate to the group you want as default and select Settings->Make Default Group.

For some reason though, the SharePoint team decided that the addition of this option would allow them to hide the "Set up Groups for this Site" page. You are shown it when you first create a site (if you select unique permissions) but seemingly can't go back after the fact. This can be a problem when you need to discover which group is the associated owners group or change it to a different group.

Luckily you can still get to this page by url: /_layouts/permsetup.aspx

Thursday, February 18, 2010

Adding items to Large Lists

So I had this blog up before, but I did some digging with a friend at Microsoft and it turns out the additemoptimized method before really wasn't optimized at all... Here is new code that really is optimized...

When you access the List.Items property in the SharePoint API (say to add a new item to a list: List.Items.Add()) this get method runs (thanks Reflector!):


public virtual SPListItemCollection Items
{
get
{
SPQuery query = new SPQuery();
query.ViewAttributes = "Scope=\"Recursive\"";
return this.GetItems(query);
}
}


That actually makes sense if you were looking for the entire SPListItemCollection for the list, but doesn't make sense if you just want to add a new item (Why query ALL items in the list if you are just adding a new one??). Additionally, this becomes a problem when you are working with Very Large Lists as this query can be SLOW and possibly lock the table.

The alternative is to write your own query to get a much smaller SPListItemCollection for the list (I wanted a helper method to give me the collection so I can call Add() on it with different params, this one will only return the schema and not pull any items):


public static SPListItemCollection AddItemOptimized(SPList list)
{
SPQuery EmptyQuery = new SPQuery();
EmptyQuery.Query = "<Where><Eq><FieldRef Name='ID'/><Value Type='Number'>0</Value></Eq></Where>";
return list.GetItems(EmptyQuery);
}


And there you go, your query now returns your SPListItemCollection ready for .Add() without querying for any items!