TFS API Part 39 – Show Deleted Items in Source Control
I got this questions a lot, if this because lots of my customers working with branches and often they delete those old branches or just because someone delete a folder and you want to see its content.
There are two ways to see deleted items from source control, the first is through Visual Studio and the second through TFS API.
See Deleted Items In Visual Studio:
First open visual studio 2010 and open source control

Navigate to –> Tools –> Options –> Source Control –> Visual Studio Team Foundation Server
Check the “Show deleted items in the Source Control Explorer” and click OK.

Now, you will see all deleted Folder\Items in Source Control as in the picture below:

See Deleted Items Using TFS API:
To obtain all deleted files you need to use VersionControlServer – Please see TFS API Part 38 – Create Label for the full example on how to get the VersionControlServer object.
private void BtnConnectClick(object sender, RoutedEventArgs e)
{
var dp = new TeamProjectPicker(TeamProjectPickerMode.NoProject, false);
dp.ShowDialog(); //Display DomainProjectPicker
if (dp.SelectedTeamProjectCollection != null)
{
tfs = dp.SelectedTeamProjectCollection;
}
}
After getting the TfsTeamProjectCollection Cast the VersionControlServer object and use the GetItems method to query all Deleted Item.
VersionControlServer vs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
//RecursionType: None = 0, OneLevel = 1,Full = 2,
//DeletedState: NonDeleted = 0, Deleted = 1,Any = 2
//ItemType: Any = 0,Folder = 1,File = 2
ItemSpec spec = new ItemSpec("$/", RecursionType.Full);
var items = vs.GetItems(spec, VersionSpec.Latest, DeletedState.Deleted, ItemType.Folder, true);
Enjoy