Click here to Skip to main content
15,441,280 members
Articles / DevOps / TFS
Posted 12 Dec 2014


3 bookmarked

TFS: Track All Changed Files in Source Control from a Date/Change Set

Rate me:
Please Sign up or sign in to vote.
4.50/5 (4 votes)
12 Dec 2014CPOL
Get a list of all files that are modified from a date or change set


This tip helps you to track all changes made on a code base from a given date (change set) on TFS.


There may be scenarios where a team of developers would want to track all the files they have added/modified from a date. My code snippet will help them to achieve this in a simple C# logic connecting to TFS.

Using the Code

Create a console application on Visual Studio.

You will have Program.cs by default. Now let's add TfsHelper.cs and put the below code into it:

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

namespace Maintenance
    public class TfsHelper
        List<string> changedFiles = new List<string>();
        public void Init(params string[] args)
            string localPath = args[0];
            string versionFromString = args[1];
            TfsTeamProjectCollection tfs = null;
            if (args.Length > 2)
                tfs = new TfsTeamProjectCollection(new Uri(args[2]));
            else return;
            VersionControlServer vcs = tfs.GetService<versioncontrolserver>();
                var changeSetItems = vcs.QueryHistory(localPath, 
                                                      0, RecursionType.Full, null, 
                                                                        null, Int32.MaxValue, true, false);
                foreach (Changeset item in changeSetItems)
                    DateTime checkInDate = item.CreationDate;
                    string user = item.Committer;
                    foreach (Change changedItem in item.Changes)
                        string filename = changedItem.Item.ServerItem.Substring
                        (changedItem.Item.ServerItem.LastIndexOf('/') + 1);
// Your choice of filters. In this case I was not interested in the below files.
                        if (!filename.EndsWith(".dll")
                            && !filename.EndsWith(".pdb")
                            && !filename.EndsWith(".csproj")
                             && !filename.EndsWith(".pubxml")
                              && !filename.EndsWith(".sln")
                               && !filename.EndsWith(".config")
                               && !filename.EndsWith(".log")
                            && filename.IndexOf(".") > -1
                            && changedItem.ChangeType.Equals(ChangeType.Edit))
                            if (!Convert.ToBoolean(args[3]))
                                filename = string.Format("{0} - {1} - {2} by {3}",
                            if (!changedFiles.Contains(filename))
                                if (Convert.ToBoolean(args[4]))
                foreach (string file in changedFiles)
            catch (Exception e)
            if (changedFiles != null && changedFiles.Count > 0)
                ("-----------------------------------------\nTotal File count: " + 
            ("-----------------------------------------\nPress any key to close");

Now from your Program.cs, call your TfsHelper as below:

 class Program
        static void Main(string[] args)
        private static void TfsChangedFiles()

       //Arguments more indetails
<code>     // args[0]</code> // local repository path
<code>     // args[1]</code> // Change sheet #(you may go with change sheet number between 1-24000+ of a date) 
<code>     // args[2]</code> // your remote TFS collections URL
<code>     // args[3]</code> // true or false - get list of concatenated "File Name+Date+change Type"
<code>     // args[4]</code> // true or false - absolute path of the file? true, else only file name

            TfsHelper TFS = new TfsHelper();
            TFS.Init(@"C:\TfsWorkSpace", "1",
                "true", "false")


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
United States United States
I am a Microsoft Certified Solution Developer, working as a “Senior .NET Solutions Architect” and hold a Doctorate in Information Technology. With an overall experience of 9+ Years in related fields. I have a tremendous desire to exceed in whatever I undertake. I am an excellent team player - I like to listen, and am open to what everyone has to offer. I am confident; not shy of taking up responsibilities. I am sincere, and give myself to the job on hand. I have the advantage of possessing good communication skills, and this gives me the confidence to deal with people. I am very artistic and creative - and I have the capability to express this in my work.

Comments and Discussions

BugNot all change types are listed? Pin
Bunny Charles19-May-15 22:16
professionalBunny Charles19-May-15 22:16 
SuggestionCredentials authentication Pin
Bunny Charles19-May-15 22:13
professionalBunny Charles19-May-15 22:13 
Questionpowershell Pin
kiquenet.com4-May-15 20:23
professionalkiquenet.com4-May-15 20:23 
QuestionGetting error "There Is no working folder mapping for tfs..." Pin
Nimit Singh Thakur2-Apr-15 19:22
MemberNimit Singh Thakur2-Apr-15 19:22 
QuestionChange sheet #(you may go with change sheet number between 1-24000+ of a date) Pin
Nimit Singh Thakur1-Apr-15 0:08
MemberNimit Singh Thakur1-Apr-15 0:08 
AnswerRe: Change sheet #(you may go with change sheet number between 1-24000+ of a date) Pin
Harsha Bopuri2-Apr-15 6:11
MemberHarsha Bopuri2-Apr-15 6:11 
GeneralRe: Change sheet #(you may go with change sheet number between 1-24000+ of a date) Pin
Nimit Singh Thakur2-Apr-15 19:19
MemberNimit Singh Thakur2-Apr-15 19:19 
GeneralRe: Change sheet #(you may go with change sheet number between 1-24000+ of a date) Pin
Bunny Charles19-May-15 22:15
professionalBunny Charles19-May-15 22:15 
QuestionC# static class Path Pin
Tableeker2-Mar-15 7:27
MemberTableeker2-Mar-15 7:27 
QuestionArguments Pin
John B Oliver7-Jan-15 10:03
MemberJohn B Oliver7-Jan-15 10:03 
AnswerRe: Arguments Pin
Harsha Bopuri7-Jan-15 10:26
MemberHarsha Bopuri7-Jan-15 10:26 
GeneralRe: Arguments Pin
John B Oliver12-Jan-15 10:48
MemberJohn B Oliver12-Jan-15 10:48 
QuestionWhy? Pin
Tony4683516-Dec-14 7:56
MemberTony4683516-Dec-14 7:56 
AnswerRe: Why? Pin
Harsha Bopuri16-Dec-14 10:58
MemberHarsha Bopuri16-Dec-14 10:58 
GeneralRe: Why? Pin
Tony4683516-Dec-14 12:12
MemberTony4683516-Dec-14 12:12 
QuestionDeployment? Pin
Joel Palmer16-Dec-14 4:45
MemberJoel Palmer16-Dec-14 4:45 
AnswerRe: Deployment? Pin
Harsha Bopuri16-Dec-14 6:12
MemberHarsha Bopuri16-Dec-14 6:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.