I am using the TFS API to get latest code files, directories, .csproj files, etc. under a TFS-bound folder.
For the same, I use something like the following:
var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(ConfigurationManager.AppSettings["TFSUrl"])); tfs.EnsureAuthenticated(); var vsStore = tfs.GetService<VersionControlServer>(); string workingFolder = @"C:\TFS\SolutionFolder"; Workspace wsp = vsStore.TryGetWorkspace(workingFolder); if (wsp != null) { ItemSet items = vsStore.GetItems(workingFolder, VersionSpec.Latest, RecursionType.Full); string relativePath = workingFolder + @"/"; foreach (Item item in items.Items) { string relativePath1 = item.ServerItem.Replace("$/TFS/SolutionFolder", relativePath); if (item.ItemType == ItemType.Folder) { Directory.CreateDirectory(relativePath1); } else { item.DownloadFile(relativePath1); } } } Now, I get the items to download and then download happens. However, I want it to be like how VS handles it - if (and only if) there is a change in a file/folder, then only download the same. With this code, I always get 'n' number of files/folders in that folder and then I overwrite the same. Wrong approach, I know. I can, however, modify this code to check for the folder's or file's last change time and then choose to either overwrite it or ignore it. That's an option, albeit a bad one at that.
Now, what I would ideally like is to get ONLY the list of files/folders that actually need to be changed i.e. the incremental change. After that, I can choose to overwrite/ignore each item in that list. So, in the present case, if a new file/folder is created (or one of the existing ones got changed inside $/TFS/SolutionFolder i.e. in the sever), then only I want to pull that item in the list of files/folders to change(and decide what I want to do with it inside C:\TFS\SolutionFolder).
Also, is using one of the overloads of VersionControlServer.QueryHistory() an option? I had something like this:
(latestVersionIdOf $/TFS/SolutionFolder) - (existingVersionIdOf C:\TFS\SolutionFolder) = (Versions that I'd go out and get back from the server, for that folder) in mind.
Any pointers will be very helpful. Thanks!