title: Get all TFS Branches programmatically in C'#
body: <p>I'm trying to programmatically get a list of all the branches in TFS for Visual Studio 2013. After doing some research I found this blog that details how to get the branches:</p>
  
  <p><a href="http://blogs.msdn.com/b/youhana/archive/2010/10/04/displaying-all-branch-hierarchies-in-tfs-2010.aspx" rel="nofollow">Displaying all branch hierarchies in TFS 2010</a></p>
  
  <p>I modified the code to instead store everything in a list. </p>
  
  <pre><code>private void Setup()
      {
          string serverName = "serverName"; //in the code this is set to the actual server name
          TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(serverName));
          VersionControlServer vcs = tfs.GetService&lt;VersionControlServer&gt;();
  
          var bos = vcs.QueryRootBranchObjects(RecursionType.OneLevel);
          Array.ForEach(bos, (bo) =&gt; DisplayAllBranches(bo, vcs));
      }
  
  private void DisplayAllBranches(BranchObject bo, VersionControlServer vcs)
      {
          _listOfBranches.Add(bo.Properties.RootItem.Item);
          var childBos = vcs.QueryBranchObjects(bo.Properties.RootItem, RecursionType.OneLevel);
          foreach (var child in childBos)
          {
              if (child.Properties.RootItem.Item == bo.Properties.RootItem.Item)
                  continue;
  
              DisplayAllBranches(child, vcs);
          }
      }
  </code></pre>
  
  <p>The problem I'm having is that the BranchObjects[] bos is always empty. Is there something I'm missing or is there a better way to get a list of all the branches?</p>