Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I programmatically check-out an item for edit in TFS?

I'm working on a utility processing files being under source control using TFS 2010.

If an item is not yet checked-out for edit, I'm getting an exception, what is definitely predictable because file is in read-only mode.

What ways exist to check-out a file?

P.S. I want something for programmatic rather then Process.Start("tf.exe", "..."); if that's applicable.

like image 224
abatishchev Avatar asked Feb 23 '11 22:02

abatishchev


People also ask

What is check out for edit?

When you begin editing a file, it is automatically checked out to you. In rare situations (for example, you want to check out and lock the file to make sure your changes are checked in before changes from other team members), you might need to manually check out (and optionally lock) an item.


1 Answers

Some of the other approaches mentioned here only work for certain versions of TFS or make use of obsolete methods. If you are receiving a 404, the approach you are using is probably not compatible with your server version.

This approach works on 2005, 2008, and 2010. I don't use TFS any longer, so I haven't tested 2013.

var workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(fileName); using (var server = new TfsTeamProjectCollection(workspaceInfo.ServerUri)) {     var workspace = workspaceInfo.GetWorkspace(server);         workspace.PendEdit(fileName); } 
like image 142
Ben Avatar answered Sep 20 '22 05:09

Ben