Hi Guy ,
You can do this using below code:-
private void GetAllMembers_Click(object sender, EventArgs e)
{
ArrayList memberGuids = new ArrayList();
IOrganizationService orgService = GetOrganizationService();
PagingInfo pageInfo = new PagingInfo();
pageInfo.Count = 5000;
pageInfo.PageNumber = 1;
QueryByAttribute query = new QueryByAttribute("listmember");
// pass the guid of the Static marketing list
query.AddAttributeValue("listid", new Guid("2CA7881F-3EDA-E111-B988-00155D886334"));
query.ColumnSet = new ColumnSet(true);
EntityCollection entityCollection = orgService.RetrieveMultiple(query);
foreach (Entity entity in entityCollection.Entities)
{
memberGuids.Add(((EntityReference) entity.Attributes["entityid"]).Id);
}
// if list contains more than 5000 records
while (entityCollection.MoreRecords)
{
query.PageInfo.PageNumber += 1;
query.PageInfo.PagingCookie = entityCollection.PagingCookie;
entityCollection = orgService.RetrieveMultiple(query);
foreach (Entity entity in entityCollection.Entities)
{
memberGuids.Add(((EntityReference)entity.Attributes["entityid"]).Id);
}
}
}
public IOrganizationService GetOrganizationService()
{
Uri organizationUri = new Uri("servername/.../Organization.svc");
Uri homeRealmUri = null;
ClientCredentials credentials = new ClientCredentials();
credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
OrganizationServiceProxy orgProxy = new OrganizationServiceProxy(organizationUri, homeRealmUri, credentials, null);
IOrganizationService _service = (IOrganizationService)orgProxy;
return _service;
}