Click here to Skip to main content
Click here to Skip to main content

Access Team Foundation Server 2010 Check in Details From C#.NET

, 17 Apr 2013
Rate this:
Please Sign up or sign in to vote.
This article explains how to retrieve TFS 2010 project check in details from C#.NET code

Introduction

Visual Studio 2010 Team Foundation Server (TFS 2010) is an enterprise-level product for managing software projects throughout the entire application lifecycle. A major requirement of TFS is source-code control, which enables developers to store code in a central repository. Source control implies version control, which keeps track of every change that has been checked in by developers. Version control allows many developers to work on the same project and the project's source-code files with a reduced risk of lost code or overwriting other developers' changes. Because source control is a core need of developers, often IT departments initially bring TFS into their organization for its source-control capabilities, sometimes we have requirement to access the TFS check in and source control details from our C# code. This tip explain how to access TFS source control check in details and changeset details.

Using the Code

Create a new Windows application using Visual Studio. Create a UI as you need like the given screenshot. Add the following DLL assemblies from the .NET tab of Add references.

Microsoft.TeamFoundation.dll
Microsoft.TeamFoundation.Build.Common.dll
Microsoft.TeamFoundation.Client.dll
Microsoft.TeamFoundation.Common.dll
Microsoft.TeamFoundation.VersionControl.Client.dll

Add the following namespaces:

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;

In Form Load event:

string TFSAddr;
private void Form1_Load(object sender, EventArgs e)
{
richTextBox1.Text = "";
dateTimePicker1.Value = DateTime.Now.Add(new TimeSpan(-30, 0, 0, 0));
dateTimePicker2.Value = DateTime.Now;
}

Create a ChangeDateFormat method for date format conversion:

private static VersionSpec ChangeDateFormat(DateTime date)
{
string Gvndate = string.Format("D{0:yyy}-{0:MM}-{0:dd}T{0:HH}:{0:mm}", date);
return VersionSpec.ParseSingleSpec(Gvndate, "");
}

Add button click event to the form:

private void button1_Click(object sender, EventArgs e)
{
richTextBox1.Text = "";
string TFSAddr = " http://testTFSServer:8080/tfs/TestApplicationProject ";
textBox2.Text = TFSAddr;
textBox2.ReadOnly = true;
TfsTeamProjectCollection TFSProjectCollection =
TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(TFSAddr));

var versionControl = TFSProjectCollection.GetService<versioncontrolserver />();

VersionSpec versionFrom = ChangeDateFormat(dateTimePicker1.Value);
 VersionSpec versionTo = ChangeDateFormat(dateTimePicker2.Value);

IEnumerable results = versionControl.QueryHistory
("$/", VersionSpec.Latest, 0, RecursionType.Full, textBox1.Text, versionFrom,
versionTo, int.MaxValue, true, true);

 List<Changeset> changesets = results.Cast<Changeset>().ToList();

if (0 < changesets.Count)
{
foreach (Changeset changeset in changesets)
{
Change[] changes = changeset.Changes;
richTextBox1.Text +=" Files contained in " +
changeset.ChangesetId + " at " + changeset.CreationDate +
" with comment " + changeset.Comment + "  Changer  "+ changeset.Owner;
richTextBox1.Text += System.Environment.NewLine;

foreach (Change change in changes)
{
string serverItem = change.Item.ServerItem;
richTextBox1.Text += serverItem + "   " + change.ChangeType;
richTextBox1.Text += System.Environment.NewLine;

}
richTextBox1.Text += System.Environment.NewLine;

}
}

}

License

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

About the Author


Comments and Discussions

 
GeneralMy vote of 5 Pinmemberbabu saravanan17-Apr-13 17:01 

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 17 Apr 2013
Article Copyright 2013 by babu saravanan
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid