balalakshmi
balalakshmi

Reputation: 4216

using TFS API, is it possible to get who has last checkedin the file

this is using TFS2010 API.

Given a file name, I need to get the details like folder path of the file, who checked in the last, datetime of last checkin.

Is there an API/WIQL that can help solve this?

Upvotes: 0

Views: 629

Answers (1)

pantelif
pantelif

Reputation: 8544

For the first part, retrieving from a filename the SourceControl path(s) to this file, I couldn't find anything other than this:

tf dir $/*file.cs /recursive /server:http://TFSServer:8080

Once you have the SourceControl path to the file, you can try this:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;

namespace ChangesetDetails
{
    class Program
    {
        static void Main(string[] args)
        {
            TfsTeamProjectCollection tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://TFSServer:8080"));
            VersionControlServer vcs = (VersionControlServer) tpc.GetService(typeof (VersionControlServer));

            IEnumerable results = vcs.QueryHistory(@"$/../file.cs", 
                                                    VersionSpec.Latest, 0, RecursionType.Full, null, null, null, int.MaxValue, true, true);
            List<Changeset> changesets = results.Cast<Changeset>().ToList();
            Changeset latestChangeset = changesets.ElementAt(0);
        }
    }
}

This shall obtain the latest Changeset of $/../file.cs, which then can reveal the properties you 're after:

string lastCommiter = latestChangeset.Owner;
DateTime dateCommited =  latestChangeset.CreationDate;

Upvotes: 2

Related Questions