in

Corey Roth and Friends Blogs

Group site for developer blogs dealing with (usually) Ionic, .NET, SharePoint, Office 365, Mobile Development, and other Microsoft products, as well as some discussion of general programming related concepts.

Kyle Kelin on .Net

Setting the People/Group Field Type to a SharePoint Group

I ran across this today and thought I would take a minute to blog about it because I didn't find exactly what I wanted by Googling. I have a SharePoint Group that I have created and I need to set that in a list so I can use it later on. I found a lot of articles on how to set a People or Group field by using the SPFieldUserValue but I didn't know how to get from a SPGroup to that object. Then it dawned on me to use the ID and Name properties of the group. Bam works like a charm. Here is the code:

 

 

SPGroup group = rootWeb.SiteGroups[groupName];

 

SPFieldUserValue value = new SPFieldUserValue(rootWeb,group.ID, group.Name);

item["Committee Group"] = value;

Comments

No Comments

Leave a Comment

(required)
(optional)
(required)
Add

About KyleKelin

Kyle Kelin has been implementing software in the Microsoft space for the past 6 years mainly as a consultant. His interests are SharePoint, .NET, JQuery, and Silverlight.
2019.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems