New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C#

Query for Files in Version Control

74 Views
Copy Code Show/Hide Line Numbers
using Microsoft.TeamFoundation.VersionControl.Client;
 
// query the version control repository for items matching a file specification
// set the folder for the root of your search
String rootFolder = "$/MyProject";
 
// construct the set of item specifications you want to search for
ItemSpec[] itemSpecs = new ItemSpec[] { 
    new ItemSpec(String.Format("{0}/*.sln", rootFolder), RecursionType.Full),
};
 
// make the call to retrieve the matching items
ItemSet[] itemSets = versionControl.GetItems(itemSpecs, 
    VersionSpec.Latest, DeletedState.NonDeleted, ItemType.File, GetItemsOptions.Unsorted);
 
foreach (ItemSet itemSet in itemSets)
{
    // cast the Items property to an IEnumerable so we can run a linq query on it
    IEnumerable<Item> items = (IEnumerable<Item>)itemSet.Items;
 
    // let's sort the results by check-in date
    var sortedItems = from item in items 
                      orderby item.CheckinDate descending 
                      select item;
 
    foreach (Item item in sortedItems)
    {
        Debug.WriteLine(item.ServerItem);
    }
}
by Jim Lamb
  October 29, 2009 @ 7:54pm
Tags:

Add a comment


Report Abuse
brought to you by:
West Wind Techologies


If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate