Get all users from a SharePoint group

I have searched for a solution to get all users from a SharePoint group and found nothing simple. Mostly all solutions are C# based. But looking on Microsoft website I discovered membership CAML clause. This was perfect fit for me. I created a SPDataSource for this and worked. See code below.

<SharePoint:SPDataSource runat="server" DataSourceMode="List" SelectCommand="&lt;View&gt;&lt;Query&gt;&lt;Where&gt;&lt;Membership Type=&quot;SPGroup&quot; ID=&quot;108&quot;&gt;&lt;FieldRef Name=&quot;ID&quot;/&gt;&lt;/Membership&gt;&lt;/Where&gt;&lt;OrderBy&gt;&lt;FieldRef Name=&quot;EMail&quot;/&gt;&lt;/OrderBy&gt;&lt;/Query&gt;&lt;/View&gt;" UseInternalName="True" ID="DSUsers">
<SelectParameters><asp:Parameter Name="ListName" DefaultValue="User Information List" /></SelectParameters>

SPDataSource above is displaying all users from SharePoint group with ID 108. Of course in your case this ID will be different. Decoded CAML looks like this.

<View><Query><Where><Membership Type="SPGroup" ID="108"><FieldRef Name="ID"/></Membership></Where><OrderBy><FieldRef Name="EMail"/></OrderBy></Query></View>

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s