How To

Get all SharePoint Users and Groups

The sample project described and attached below will enable you to get a list of all the security groups in your SharePoint site and the users contained within those groups.

Requires version 3.0.1250 and higher & will only work with SharePoint On-Prem

To enumerate a list of SharePoint Groups and the users listed within these you can use the demo project available here: Get All Groups and Members

This project makes use of the SharePoint Security Groups Connector to get the members for each group.

This version will override the data loading in Dynamic Columns and call it multiple times for each group, thereby creating an aggregated result.

partial class DataSourceRowOverride : Simego.DataSync.DynamicColumns.DataSourceRowInternal //Do Not Change This Line
	public string MyGroupName { get; set; }
	public override DataTableStore GetDataTable(DataTableStore dt, IDataSourceReader reader)
		var r = GetDataSourceA();		
		// Use reflection to get a List of Groups from the Connector
		var b = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod;
		var groups = r.GetType().InvokeMember("GetGroups", b, null, r, null) as IList<string>;
		foreach(var g in groups)			
			// Set the Group Name 
			MyGroupName = g;
			// Set the Group Name on the connector
			r.UserGroup = MyGroupName;
			// Append the Members to the DataTable
			dt = base.GetDataTable(dt, reader);	
		return dt;