4

Hi I am trying to create new workitems via the TFS API and this is the method I have used below to get a list of valid users who can be assigned workitems. Somehow, it gives me a null reference exception on validUserSids line. Anyone know what's wrong here?

private string[] TFSUsers(string server)
    {
        // Get a Reference to Team Foundation Server.
        TeamFoundationServer tfs = tfsdata.GetTFS(server);
        // Get a reference to Group Security Service.
        IGroupSecurityService gss = (IGroupSecurityService)tfs.GetService(typeof(IGroupSecurityService));
        // Resolve to SIDs
        Identity validUserSids = gss.ReadIdentity(SearchFactor.AccountName, "TFS Valid Users", QueryMembership.Expanded);
        // Resolve to actual users
        Identity[] validUsers = gss.ReadIdentities(SearchFactor.Sid, validUserSids.Members, QueryMembership.None);
        List<string> Users = new List<string>();
        foreach (Identity user in validUsers)
        {
            Users.Add(user.DisplayName);
        }
        return Users.ToArray();
    }
jessehouwing
  • 106,458
  • 22
  • 256
  • 341
TS.
  • 149
  • 4
  • 16

1 Answers1

6

Here's how you would get the list of users in TFS:

var tfs = TeamFoundationServerFactory.GetServer("http://vstspioneer:8080/tfs/VSTSDF");
var workItemStore = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
var allowedValues = workItemStore.FieldDefinitions[CoreField.AssignedTo].AllowedValues;

foreach (String value in allowedValues)
{
    Console.WriteLine(value);
}
Jim Lamb
  • 25,355
  • 6
  • 42
  • 48
  • Thanks a lot! That was definitely easier. How else to use the concept of Identities wth Group Security Service like I did? I realised that my account name was wrong and should have been "Team Foundation Valid Users" OR "Project Collection Valid Users", but it still didn't work. Any suggestions? – TS. Oct 15 '09 at 04:52