3

How do i check if all the files in a folder are latest or not. I need to put up a condition in C# code which should get latest version of the project only if there is any file in the project folder having the latest as "No"?

Any help wpould be greatly appreciated.

  • Similar https://stackoverflow.com/questions/14016329/how-to-check-whether-a-local-file-is-the-latest-version-in-tfs – jophab Feb 04 '18 at 15:52

1 Answers1

4

There's a few ways that you could do this programmatically, but the easiest way is to let the server determine this for you: if you perform a get latest with the preview get option set, it will not actually perform the get, it will simply tell you what would be retrieved to bring you up to the latest version.

For example:

GetStatus status = workspace.Get(new GetRequest(null, VersionSpec.Latest), GetOptions.Preview);

if(status.NumOperations == 0)
{
    /* All files up to date. */
}
else
{
    /* We are not up to date on some files. */
}
Edward Thomson
  • 74,857
  • 14
  • 158
  • 187
  • I tried that. But even if the folder is latest the property returns me a value greater than 0. In both cases the value is greater than 0. Below is the code GetStatus s1 = workspace.Get(new GetRequest(new ItemSpec(strLocalWorkspacePath, RecursionType.Full), VersionSpec.Latest), GetOptions.GetAll | GetOptions.Overwrite); int i = s1.NumOperations; – Ajay Kankaria Jul 22 '11 at 03:16
  • Don't use GetOptions.GetAll. That will force a get even if you're latest. In fact, if your only goal is to *discover* whether you need to do a get, not actually *do* the get, then you need to use GetOptions.Preview, which is incompatible with both GetOptions.GetAll and GetOptions.Overwrite. – Edward Thomson Jul 22 '11 at 13:58