Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list files of a team project using tfs api?

Tags:

c#

api

tfs

I am wondering if there is a way for me to list all 'files' containted in a tfs team project. What I am aiming to do is search for files of a particular name that dont have fixed paths within TFS caused by branching ($/MyTeamProject/Main/Build/instruction.xml and $/MyTeamProject/Branches/Release_1.0). Once a file would be found I would like to manipulate it.

I guess that we are talking items when it comes to entities containted within a team project and not traditional files and therefore this might be a bit tricky?

I have seen some samples for manipulating a file but all samples so far have fixed paths.

like image 424
Fadeproof Avatar asked Jan 22 '09 16:01

Fadeproof


1 Answers

This is not a different answer, but simply an upgrade of Vengafoo's code. The TeamFoundationServer class is obsolete in 2011 (not sure when this happened, I just know it is obsolete as of now). Vengafoo's code is from 2009, so that makes sense. Use the TfsTeamProjectCollection class with the TfsTeamProjectCollectionFactory factory class instead.

Here is the upgrade, just one line of change:

//TeamFoundationServer server = new TeamFoundationServer("server");
TfsTeamProjectCollection server = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://tfsServerURI:8080/tfs/"));

VersionControlServer version = server.GetService(typeof(VersionControlServer)) as VersionControlServer;

ItemSet items = version.GetItems(@"$\ProjectName", RecursionType.Full);
//ItemSet items = version.GetItems(@"$\ProjectName\FileName.cs", RecursionType.Full);

foreach (Item item in items.Items)
{
    System.Console.WriteLine(item.ServerItem);
} 
like image 128
dyslexicanaboko Avatar answered Sep 27 '22 17:09

dyslexicanaboko