Get Branch Relatives from TFS Version Control

In this post I will Implement how to get server path branches and branch history from version control in tfs

1. Add the connect method to the form from this
2. Use this Code to get the information

DataTable _data = new DataTable(”Branches”);
_data.Columns.Add(”Branch Path”,typeof(string));
_data.Columns.Add(”Created Date”, typeof(DateTime));
_data.Columns.Add(”ChangesetId”, typeof(int));

string path = “VERSION CONTROL BRANCH PATH”;
ItemSpec _item = new ItemSpec(path, RecursionType.None);

ItemSpec[] _items = { _item };
BranchHistoryTreeItem[][] _branchItems;
BranchHistoryTreeItem _branchsItem;

_branchItems = version.GetBranchHistory(_items, VersionSpec.Latest);

List listBranches = new List();
int _childs = _branchItems[0][0].Children.Count;
if (_childs > 0)
{
_branchsItem = _branchItems[0][0];
_branchsItem = _branchsItem.GetRequestedItem();
foreach (BranchHistoryTreeItem items in _branchsItem.Children)
{
if ((items.Relative.BranchToItem != null) && (items.Relative.BranchToItem.DeletionId == 0))
{
listBranches.Add(items.Relative.BranchToItem);
_data.Rows.Add(items.Relative.BranchToItem.ServerItem, items.Relative.BranchToItem.CheckinDate, items.Relative.BranchToItem.ChangesetId);
}
}
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *