Recently our company had a need to create a clean TFS project for a new AX environment, and I have found out that there is no simple way of listing objects that were deleted from the repository. We had to make sure that these objects do not land in the new AX environment, so I had to figure out how to collect these objects.

I came across this blog post on how to use the Team Foundation Server API in .Net C#, which turned me in the right direction to be able to list the deleted XPO files:

Here is the final code, which allows you to connect to a TFS 2010 instance and pick a project, then dump all the removed files to a text document. You need to include the Microsoft.TeamFoundation, Microsoft.TeamFoundation.Client, Microsoft.TeamFoundation.Common, Microsoft.TeamFoundation.VersionControl.Client, System.Windows.Forms references in your console application:

using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;

namespace TFSGetDeletedFiles
    class Program

        static void Main(string[] args)
            TfsTeamProjectCollection tfs;
            VersionControlServer vcs;
            TeamProjectPicker tPicker = new TeamProjectPicker(TeamProjectPickerMode.SingleProject, false);


            if (tPicker.SelectedTeamProjectCollection != null)
                tfs = tPicker.SelectedTeamProjectCollection;
                vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

                VersionControlServer vs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

                ItemSpec spec = new ItemSpec(String.Format("$/{0}/",
                    tPicker.SelectedProjects[0].Name), RecursionType.Full);
                ItemSet itemset = vs.GetItems(spec, VersionSpec.Latest,
                    DeletedState.Deleted, ItemType.File, true);
                Item[] itemArray = itemset.Items;

                String path = @"C:\temp\deletedfiles.txt";
                System.IO.StreamWriter file = new System.IO.StreamWriter(path);
                foreach (var item in itemArray)


            System.Console.WriteLine("Press enter to finish");