Click here to Skip to main content
15,890,186 members
Articles / Programming Languages / C#
Tip/Trick

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

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
26 Nov 2012CPOL 15.9K   135   5   2
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)


Written By
Software Developer (Senior)
Indonesia Indonesia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionMissing download Pin
Smitha Nishant26-Nov-12 4:57
protectorSmitha Nishant26-Nov-12 4:57 
Hello author

Could you please reupload the source file? The file is currently missing.

Thanks
Smitha Vijayan
The Code Project
Are you an aspiring author? Read how to submit articles to CodeProject: Article Submission Guidelines[^]

More questions? Ask an editor here.../xml>

AnswerRe: Missing download Pin
efero26-Nov-12 15:04
efero26-Nov-12 15:04 

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.