Jean Paul's Blog

There are 2 types of People in the World, One who Likes SharePoint and..

  • Microsoft MVP

  • MindCracker MVP

  • CodeProject MVP

  • eBook on SharePoint 2010

  • eBook on Design Patterns

  • eBook on Windows Azure

  • NLayers Framework @ CodePlex

  • MSDN Forums

  • .Net vs. Java

    Due to Public Demand
  • Advertisements

TFS :: Programmatically get folder content

Posted by Paul on April 20, 2012

In this small article, I would like to show you how to get the contents of the folder from TFS server.

The post could be useful while creating deployment tools.

1. Create a new Console Application

2. Add references to following assemblies

You can get those from the references assembly or from folder 
C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0
3. Get the TFS server url 
Use Team Explorer to connect to a TFS server and use Properties window to the get the url.
4. Get the path to required folder
Get the folder path from Source Control Explorer
Eg: $/Projects/MyApplication
5. Use the following code to retrieve all folders
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
namespace MyConsoleApp
{     class Program     {         static void Main(string[] args)         {             RegisteredProjectCollection server = RegisteredTfsConnections.GetProjectCollection(new Uri("URLHER"));             TfsTeamProjectCollection projects = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(server);             VersionControlServer versionControl = (VersionControlServer)projects.GetService(typeof(VersionControlServer));             Workspace workspace = versionControl.CreateWorkspace(AppDomain.CurrentDomain.FriendlyName + "-installer", versionControl.AuthorizedUser);             WorkingFolder folder = new WorkingFolder("$PATH", "c:\\output");             workspace.CreateMapping(folder);             workspace.Get(); // Receive all the files             workspace.Delete();         }     }
6. Execute the application
Now you can see the c:\output folder to view the files.
var dzone_url = ‘’;var dzone_title = ‘TFS :: Programmatically get folder content’;var dzone_blurb = ‘TFS :: Programmatically get folder content’;var dzone_style = ‘2’;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s