Search code examples
c#.nettfsvcs-checkout

TFS: Get the user's name of locked file


While trying to checkout a file \ folder in a Workspace, I get 0 as a result if the action was failed. Usually it fails because someone else already checked it out with lock.

Welp, I would like to know who is this user (to bump his ass). How do I do that?

My code:

var workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(folder);
var server = new TfsTeamProjectCollection(workspaceInfo.ServerUri);
var workspace = workspaceInfo.GetWorkspace(server);
int result = workspace.PendEdit(new[] { jsonFile }, RecursionType.Full, null, LockLevel.CheckOut);
if (result == 0)
{
    // How to get the user's name ?
}

Solution

  • TfsTeamProjectCollection coll = YOURTEAMPROJECTCOLLECTION;
    
    PendingSet[] pending = coll
            .GetService<VersionControlServer>()
            .QueryPendingSets(new[] { jsonFile  }, RecursionType.None, null, null);
    

    'pending' will contain any pending changesets, who has it checked out, etc.