How can I determine programatically which branch this file belongs to? I've spent 3 hours trying to figure this out with no results. I found this topic but it's not what I want: How to programmatically get information about branches in TFS?
I had a very similar problem. I found a solution to it, 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 the op has already solved it (it's been a while since he asked the question).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With