Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

How to Search Information from TFS based on Change Set and Comment

5.00/5 (1 vote)
26 Nov 2012CPOL 16.4K   135  
How to search information from TFS based on Change Set and comment.

Introduction

Before I created this project, I had problems when I checked-in many files in TFS and I had to register the file names to the tracker project. This project allows a TFS user to find what file has been checked-in to TFS by filtering on the change set and allows the user to find his history based on comments. The user can know which change sets or the history of their work.

In this UI, user can find two list boxes, one is display containing .cs, and the other contains .sql.

Image 1

Using the Code

C#
private void WorkWithTFS(string login, string password, string tfsName)
{
    NetworkCredential tfsCredential = new NetworkCredential(login, password);
    TeamFoundationServer tfs = new TeamFoundationServer(tfsName, tfsCredential);
    tfs.Authenticate();

    Type type = typeof(VersionControlServer);
    VersionControlServer versionControl = (VersionControlServer)tfs.GetService(type);
  
    Changeset changeSets = versionControl.GetChangeset(int.Parse(txtChangeset.Text));

    lblCheckin.Text = changeSets.CreationDate.ToString("dd.MM.yyyy HH:mm:ss");
    lblComment.Text = changeSets.Comment;
    lblCommit.Text = changeSets.Committer;

    lbChangeItem.Items.Clear();
    lbSQLItem.Items.Clear();
    for (int i = 0; i < changeSets.Changes.Count(); i++)
    {
        if (changeSets.Changes[i].Item.ServerItem.Contains("aspx") || 
            changeSets.Changes[i].Item.ServerItem.Contains("cs"))
        {
            lbChangeItem.Items.Add(changeSets.Changes[i].Item.ServerItem);
        }
        else
        {
            lbSQLItem.Items.Add(changeSets.Changes[i].Item.ServerItem);
        }
    }
} 

UI Find Tracker History by Comment

Image 2

Using the Code

C#
Encrip encrip = new Encrip();
string server = ConfigurationSettings.AppSettings.GetValues("Server")[0];
string login = ConfigurationSettings.AppSettings.GetValues("Login")[0];
string urlTracker = ConfigurationSettings.AppSettings.GetValues("urlTracker")[0];

string encrpString = encrip.Decrypt(ConfigurationSettings.AppSettings.GetValues("Pass")[0]);
string pass = encrpString;

TeamFoundationServer tfs = new TeamFoundationServer(server, new NetworkCredential(login, pass));
Type type = typeof(VersionControlServer);
VersionControlServer versionControl = (VersionControlServer)tfs.GetService(type);
IEnumerable changeSets = versionControl.QueryHistory(urlTracker,
    VersionSpec.Latest, 0, RecursionType.Full,
    null, null, null, int.Parse(txtDepth.Text), true, false);

lbfileCheckin.Items.Clear();
int i = -1;
foreach (Changeset data in changeSets)
{
    i++;
    if (data.Comment.Contains(txtBugID.Text))
    {
        lbfileCheckin.Items.Add(FillSpaceToValue(data.ChangesetId.ToString(), 8) + "| " +
            FillSpaceToValue(data.Owner, 20) + "| " +
            FillSpaceToValue(data.Comment, 60) + "| " + 
            data.CreationDate.ToString("dd.MM.yyyy HH:mm:ss"));
    }
}

Points of Interest

Through this program, I hope I can share my knowledge with everyone.

License

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