Question

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.

Was it helpful?

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

OTHER TIPS

(I'm assuming you're referring to TFS 2012)

There's an article in the 2013 MSDN Magazine that should give you a decent starting point - http://msdn.microsoft.com/en-us/magazine/jj883959.aspx

By the way, if you want to delete team projects I'd strongly recommend you use TFSDeleteProject (http://msdn.microsoft.com/en-us/library/ms181482.aspx) since you'll be using a supported tool.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top