4

I can't figure out any way to force get a file from TFS programmatically. My current code:

_workspace.Get(new GetRequest(serverPath, RecursionType.None, new DateVersionSpec(dateTime)), GetOptions.Overwrite);

The above code will get a specific version, but if I manually delete the file, TFS thinks its still there. How can I use a force get for a specific version?

riQQ
  • 9,878
  • 7
  • 49
  • 66
NYTom
  • 524
  • 2
  • 14

2 Answers2

5

To do a force get, use GetOptions.GetAll. Eg:

workspace.Get(new GetRequest(serverPath, RecursionType.None, new DateVersionSpec(dateTime)), GetOptions.Overwrite | GetOptions.GetAll);
Edward Thomson
  • 74,857
  • 14
  • 158
  • 187
-1

I actually figured it out. The problem with using GetAll is, that it gets all and I just want one specific version of a specific file.

This is what I did:

_controlServer.GetItems(serverPath, new DateVersionSpec(dateTime), RecursionType.None).Items[0].DownloadFile(_workspace.GetWorkingFolderForServerItem(serverPath).LocalItem);
DaveShaw
  • 52,123
  • 16
  • 112
  • 141
NYTom
  • 524
  • 2
  • 14
  • Because if you call Get() then TFS will only update the file if its thinks it should. The way I mentioned above is like a force get on just one file. – NYTom Dec 23 '12 at 21:44
  • That's what `GetOptions.GetAll` is for, actually. – Edward Thomson Dec 24 '12 at 00:47
  • The mechanism you propose will not update the file in your workspace - it will only download the file to disk and you will be left with a writable file conflict. – Edward Thomson Dec 24 '12 at 01:02
  • Edward, thanks for the reply. That is very true about the download() causing issues when it becomes writable. But I believe GetOptions.GetAll will get all files, which would be a very bad thing since the other files sizes are very big. I used Download() which returns a stream and sent the stream to the user, so in that case I wont have the issue you mentioned. – NYTom Dec 24 '12 at 14:17
  • What do you mean by "all files"? You will only get the `ItemSpec`s specified, but it will get all of them ("force get") them, regardless of whether they're already up to date. If you don't want all those items, pass the `ItemSpec`s you do want. – Edward Thomson Dec 24 '12 at 16:04
  • Ok, my assumption was GetAll was at a scope of the workspace, not the ItemSpec. – NYTom Dec 26 '12 at 15:47