TFS 2010 programmatically defining an element branch

How can I programmatically determine which branch this file belongs to? I spent 3 hours trying to figure it out to no avail. I found this topic, but that’s not what I want: How to get branch information in TFS programmatically?

+5
source share
2 answers

I had a very similar problem. I found a solution for this, here is the code:

...
// get all branches
VersionControlServer vcs = tfs.GetService(typeof(VersionControlServer));
BranchObject[] allBranches = vcs.QueryRootBranchObjects(RecursionType.Full);

string myItem = "$/My Project/some Path including the branch/myFile.txt";

foreach(BranchObject branch in allBranches)
{
  if(myItem.Contains(branch.Properties.RootItem.Item))
  {
    // branch is the branch to which the item belongs! :)
  }
}
...

I hope this helps someone with this problem, I think op has already solved this (some time has passed since he asked the question).

+4
source

- VersionControlServer.QueryBranchObjects .

- tfs 2010. , , .

+2

All Articles