ZaraQ
ZaraQ

Reputation: 57

How to select all users from TFS into a list?

I want to make a list of all users of TFS irrespective of the fact if they have any changesets or not. I want all the users in my list, using C# and MVC. How do I do this?

Upvotes: 0

Views: 1338

Answers (1)

MikeR
MikeR

Reputation: 3075

Here is a way how I list all user of a collection (reference Microsoft.TeamFoundation.Client.dll):

IIdentityManagementService ims = (IIdentityManagementService)tfsConnection.GetService(typeof(IIdentityManagementService));
// get all valid users of the collection
TeamFoundationIdentity SIDS = ims.ReadIdentity(IdentitySearchFactor.AccountName, "Project Collection Valid Users", MembershipQuery.Expanded, ReadIdentityOptions.ExtendedProperties);
List<string> ids = new List<string>();
foreach (var member in SIDS.Members)
{
    ids.Add(member.Identifier);
}

// get user objects for existing SIDS
TeamFoundationIdentity[][] UserId = ims.ReadIdentities(IdentitySearchFactor.Identifier, ids.ToArray(), MembershipQuery.None, ReadIdentityOptions.ExtendedProperties);
// convert to list
List<TeamFoundationIdentity> UserIds = UserId.SelectMany(T => T).ToList();

foreach (TeamFoundationIdentity user in UserIds)
{
  // exclude groups in listing
  if (!user.IsContainer)
  {
    //do what you want with the user
  }
}

Upvotes: 1

Related Questions