Drag13
Drag13

Reputation: 5978

TFS 2015. Get CollectionName by item

I have next situation and I am stack.

I am using Microsoft.TeamFoundation classes to get workitems from stored query with c#. I know server name, project name and stored query name. So I can execute stored query and receive all WorkItems.

But than I have to create a direct link to this item. According to the documentation, this link should be like

http:// ServerName:8080/tfs/CollectionName/ProjectName/_workitems/edit/Id

So, before executing query I know ServerName, ProjectName and work item's Id. But I cant find ProjectName anywhere.

So my question is. How, knowing ServerName, ProjectName, WorkItemId and Stored Query name get CollectionName?

Or. How to create link to the work item knowing ItemsId?

P.S. GetArtifactUrl is not the right way.

Thanks for help!

Upvotes: 1

Views: 260

Answers (1)

PatrickLu-MSFT
PatrickLu-MSFT

Reputation: 51073

Afraid there is no such API to achieve this. However, as a workaround, you can list all collection's name through client API such as below:

        Uri configurationServerUri = new Uri(URL);
      TfsConfigurationServer configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(configurationServerUri);
                                    ITeamProjectCollectionService tpcService = configurationServer.GetService<ITeamProjectCollectionService>();

    foreach (TeamProjectCollection tpc in tpcService.GetCollections())
                                {
                                    ListCollection.Add(tpc.Name);
                                }

More ways for your reference:

Upvotes: 2

Related Questions