Search code examples
tfslocksvcs-checkout

Using TFS Client Object Model to get who has currently checked out a file


I am using the 2012 edition of the TFS Client Object Model to retrieve some file information within repositories. Given a string specifying the path to a file in a TFS project, I'd like to find out who has checked out a file if it is locked. I use VersionControlServer.GetItems(...).Items and a Where predicate to get only the files (not folders) I am interested in.


Solution

  • QueryPendingSets is your friend!

    Sample:

    PendingSet[] queryPendingSets = versionControlServer.QueryPendingSets(new [] {"$/A/B/C.txt"},RecursionType.None, null, null );
    

    This lists all pending changes for the specified file. You can get them all by looking at:

    queryPendingSets[0].PendingChanges