How to get the History of the sourcecontrol in TFS API?

.net, tfs, tfs-sdk, visual-studio

Solution

I Don't know how to check when was the last time a user connected to the project, but this how you can access the source control history from code,

using Microsoft.TeamFoundation.Client; 
using Microsoft.TeamFoundation.VersionControl.Client;
using System.Collections;
using System.Windows.Forms;

//The example function is very simple: It gets a change and shows message boxes of all the changesets that have a change for the specified file up to the change transferred to the method.

//Note: Change the [Server Name] with your TFS name.

    public void GetChangesetsOfFile(Change theChange)
    {  
      //Query History parameters

      TeamFoundationServer tfs = new TeamFoundationServer 
                    ("[Server Name]");

      VersionControlServer VCServer = 
                    (VersionControlServer)tfs.GetService 
                    (typeof(VersionControlServer)); 

      int changeId = (theChange.Item.DeletionId != 0) ? 
                    theChange.Item.ChangesetId - 1 :  
                     theChange.Item.ChangesetId;

      ChangesetVersionSpec version = new  
                            ChangesetVersionSpec(changeId);
      ChangesetVersionSpec versionFrom = new 
                            ChangesetVersionSpec(1);
      string path = theChange.Item.ServerItem;

      //Query History Command
      IEnumerable changesets = VCServer.QueryHistory(path, 
               version, 0, RecursionType.None, null, 
               versionFrom, LatestVersionSpec.Latest, 
               int.MaxValue, true, false);


      foreach (Changeset cSet in changesets) 
      { 
        MessageBox.Show(cSet.Changes 
            [0].Item.ChangesetId.ToString()); 
      } 
    }

Reference

http://blogs.microsoft.co.il/blogs/srlteam/archive/2009/06/14/how-to-get-a-file-history-in-tfs-source-control-using-code.aspx

Problem

I'm new using the TFS API, I'm writting an app who delete my team projects, but before I delete I want to know the last time was merged I mean the info that appear in Source Control Explorer > "Sample Project" > view history, and put into a textbox. Also the info of the last time a user entered the project.

Original source