i want to get all the users with there Iteration in a project.
Lets say Project 'Precient' has 9 distinct users with 20 iteration so i want distinct users with all the Iteration in the project WIQL C#
.it's related to the Question.
WIQL query to get all the team and the users in a Project?
but does not help me fully
Asked
Active
Viewed 1,298 times
2
-
Please provide the code you have tried and explain exactly what didn't work as expected. – Mary Apr 14 '18 at 04:10
2 Answers
1
You may get that through REST API or Net API. This is sample for Net API.
- You may get all users from group "Project Valid Users"
You may get all Iterations from Project root Iterations.
using Microsoft.TeamFoundation.Client; using Microsoft.TeamFoundation.Framework.Client; using Microsoft.TeamFoundation.Framework.Common; using Microsoft.TeamFoundation.Server; using Microsoft.TeamFoundation.WorkItemTracking.Client; using System; using System.Collections.Generic; namespace GetUserіAndItearions { class Program { public class Iteration { public string Path; public DateTime DateFrom; public DateTime DateTo; } static void Main(string[] args) { string _teamProject = "Your_Project_Name"; try { TfsTeamProjectCollection _tpc = new TfsTeamProjectCollection(new Uri("http://your_server:8080/tfs/DefaultCollection")); GetAllUsers(_tpc, _teamProject); GetAllIterations(_tpc, _teamProject); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); Console.WriteLine(ex.StackTrace); } } private static void GetAllIterations(TfsTeamProjectCollection pTpc, string pProjectName) { List<Iteration> _its = new List<Iteration>(); WorkItemStore _wistore = pTpc.GetService<WorkItemStore>(); var _css = pTpc.GetService<ICommonStructureService4>(); foreach (Node _node in _wistore.Projects[pProjectName].IterationRootNodes) FillIterations(_css, _node, _its); Console.WriteLine("Iterations:"); foreach (Iteration _it in _its) Console.WriteLine("{0}:{1}-{2}", _it.Path, (_it.DateFrom == DateTime.MinValue) ? "0" : _it.DateFrom.ToShortDateString(), (_it.DateTo== DateTime.MinValue) ? "0" : _it.DateTo.ToShortDateString()); } private static void FillIterations(ICommonStructureService4 pCss, Node pNode, List<Iteration> pIts) { var _nodeInfo = pCss.GetNode(pNode.Uri.AbsoluteUri); pIts.Add(new Iteration { Path = _nodeInfo.Path, DateFrom = (_nodeInfo.StartDate == null) ? DateTime.MinValue : (DateTime)_nodeInfo.StartDate, DateTo = (_nodeInfo.FinishDate == null) ? DateTime.MinValue : (DateTime)_nodeInfo.FinishDate }); if (pNode.HasChildNodes) foreach (Node _node in pNode.ChildNodes) FillIterations(pCss, _node, pIts); } private static void GetAllUsers(TfsTeamProjectCollection pTpc, string pProjectName) { List<string> listUsers = new List<string>(); WorkItemStore _wistore = pTpc.GetService<WorkItemStore>(); var _gss = pTpc.GetService<IIdentityManagementService>(); var _teamProject = _wistore.Projects[pProjectName]; string _validGroupName = "[" + pProjectName + "]\\Project Valid Users"; TeamFoundationIdentity _group = _gss.ReadIdentity(IdentitySearchFactor.DisplayName, _validGroupName, MembershipQuery.Expanded, ReadIdentityOptions.ExtendedProperties); List<string> _memebersIds = new List<string>(); foreach (var _member in _group.Members) _memebersIds.Add(_member.Identifier); var _members = _gss.ReadIdentities(IdentitySearchFactor.Identifier, _memebersIds.ToArray(), MembershipQuery.Expanded, ReadIdentityOptions.ExtendedProperties); foreach (var _member in _members) if (!_member[0].IsContainer) listUsers.Add(_member[0].DisplayName); Console.WriteLine("Users:"); foreach (var _user in listUsers) Console.WriteLine("{0}", _user); } } }

Shamrai Aleksander
- 13,096
- 3
- 24
- 31
-
need ur help here https://stackoverflow.com/questions/52025525/how-to-find-the-field-detail-of-a-product-backlog-item-tfs-by-wiql – Aug 26 '18 at 10:57
1
It's not able to get users from Team via WIQL. WIQL is a work item query language which used to query for bugs, tasks, other types of work items. The return value should be work item.
You need use api as @Shamray provided to retrieve the users. The following blog also provided an example:
http://blogs.microsoft.co.il/shair/2012/05/20/tfs-api-part-44-vs11-teams-and-team-members/

Cece Dong - MSFT
- 29,631
- 1
- 24
- 39
-
-
i am using TFS 2015 !! pls write C# code to connect TFS by REST api and get all users and iteration of a project – Mar 23 '18 at 16:20
-
You could use **Basic** Authentication with your windows credential in your api. The rest api you should refer to [Get a list of teams](https://www.visualstudio.com/en-us/docs/integrate/api/tfs/teams#get-a-list-of-teams), [Get a team's members](https://www.visualstudio.com/en-us/docs/integrate/api/tfs/teams#get-a-teams-members), [Get a team's iterations](https://www.visualstudio.com/en-us/docs/integrate/api/work/iterations). Regarding how to use a REST api in C# code, please refer to this website: https://docs.microsoft.com/en-us/vsts/integrate/get-started/client-libraries/samples?view=vsts – Cece Dong - MSFT Mar 26 '18 at 09:07