This is another way to check whether a given file is latest or not.
string file_path = @"your_file_path";
WorkspaceInfo info = Workstation.Current.GetLocalWorkspaceInfo(file_path);
Workspace ws = info.GetWorkspace(new TfsTeamProjectCollection(info.ServerUri));
GetStatus status = ws.Get( new GetRequest(
new ItemSpec ( file_path, RecursionType.Full ),
VersionSpec.Latest ),
GetOptions.Preview );
if(status.NoActionNeeded)
MessegeBox.Show("Latest");
else
MessegeBox.Show("Not Latest");
STEPS
1) We need to get the Workspace
that contains the file path. We use
Workstation.GetLocalWorkspaceInfo Method (String)
to get WorkspaceInfo
object which contains properties of the Workspace that contains the specified file.
We can use this WorkspaceInfo
object to get the instance of that workspace by using
WorkspaceInfo.GetWorkspace Method (TfsTeamProjectCollection)
2) Now we need to perform a Get
Operation with the workspace object.
Workspace.Get Method (GetRequest[], GetOptions)
The second parameter, GetOptions
has six possible member values. Each with a purpose.
Since you don't need to download the file,
we will use the member value Preview
which Executes a get without modifying the disk.
3) The Get
operation returns a GetStatus
object which represents the status of a Workspace.Get
operation.
This contains information about how many operations, conflicts, errors, and so on occurred when the Get
operation was being processed.
GetStatus
object has a number of properties. We use property called NoActionNeeded
which gets a flag that indicates whether no failures and no operations occurred.
The flag value will be True if no operations or errors occurred. ie, the file is already the latest version. Otherwise the flag will be False which means the file is not the latest version available in TFS.