Pages

Monday, August 12, 2013

How to retrieve the SPGroup Description

In this days I worked on a timer job that sync the groups from a site collection to another.
For the first time on my life, copy the description of the group to another was a software requirement.

My expectation was copy the description from the property Description of the SPGroup class:

10-08-2013 10-29-57

10-08-2013 11-18-18

and set the description of the new group by the same property after that I created it. But if you use it the description that is not show on the group page:

10-08-2013 11-22-27

to do that we should work with the property SiteUserInfoList of SPWeb class:

var g = syncWeb.SPWeb.SiteGroups [ "Group Name" ];
var text = ( SPFieldMultiLineText )syncWeb.SPWeb.SiteUserInfoList.Fields [ SPBuiltInFieldId.Notes ];
SPListItem groupItem = syncWeb.SPWeb.SiteUserInfoList.GetItemById ( g.ID );
map.Description = text.GetFieldValueAsText ( groupItem [ text.InternalName ] );


into map.Description we will have the html for the About me column, but we can use it when we need have to create a new group as:

SPWeb.SiteGroups.Add ( group.Name, adm, adm,
string.Format ( "{0} {1}", group.Description, Constants.GROUP_SYNC_DESC ) );

enjoy

No comments:

Post a Comment