Get a file from TFS without a workspace
August 17, 2006 at 2:23 am | In Team Foundation Server |I’m currently working with a client to replace their Visual SourceSafe source code control system with Team Foundation Server. Along the way we’re finding that we need to replace existing VSS customisations with their TFS equivalents.
One particular process uses batch scripts to grab the latest copy of a config file from VSS and copy it to a staging server.
Existing command
- ss.exe Get $/Project/Config.xml
TFS equivalent
My first thought was “great! I can just use tf.exe get“, however tf.exe requires that a workspace be created before you can grab a copy of the file.
Fortunately Item.DownloadFile() lets you grab a file without creating a workspace.
// Do the download
Item item = versionControl.GetItem(tfsPathToDownload);
item.DownloadFile(destinationFileName);
TfsDownloadFile.exe
I’ve created a simple exe that can be used by your batch scripts to grab the latest copy of a file without creating a workspace. Optionally you can specify an output filename to write to.
Usage
TfsDownloadFile [server] [path] <output filename>
TfsDownloadFile http://server:8080/ $/TeamProject/config.xml
Get the source
Download from the ProjectDistributor project page. Direct download v1.0 Source and Binaries here.
Feedback
Let me know if you find this useful by leaving a comment. Any feedback or suggestions are welcome.
5 Comments »
RSS feed for comments on this post. TrackBack URI
Leave a comment
Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.

Fantasic! Thanks for sharing. I looked an looked and could not find… until I hit this post. Thanks for the explanation and the code!
Comment by nathan — February 1, 2007 #
hi,how to checkout, checkin & checkout a file programmatically
Comment by krish — July 12, 2007 #
Hi Grant,
You might remember me from your DEWR days, and I’m interested to know if it is possible to check out a whole directory without using a workspace.
Cheers.
Comment by Luke Elliott — December 12, 2007 #
tf dir does not need a workspace, so in order to get a whole directory, use it to gather its contents into an array, running this utility on each.
Would be nice to be able to get a speciffic version of an object using this tool.
Regards
Jon
Comment by Jon J Bjarnason — April 23, 2008 #
Jon - You could easily download the source, add another parameter and change:
versionControl.GetItem(tfsPathToDownload) to:
versionControl.GetItem(tfsPathToDownload, args[3])
See:
http://msdn2.microsoft.com/en-us/library/bb138927.aspx
Comment by Grant Holliday — April 24, 2008 #