Q:

How to Use the TFS SDK to Determine If a Checked Out File Has Changed

I have a tool that generates C# files.  I've been able to programmatically checkout the file
using this method:
private static void CheckoutFile(string fileName)
{
    var workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(fileName);
    var server = new TfsTeamProjectCollection(workspaceInfo.ServerUri);
    var workspace = workspaceInfo.GetWorkspace(server);

    workspace.PendEdit(fileName);
}

But after the file has been generated I want to determine if there has been any changes to the file, and if not, to undo the check out.  How do I do that with the TFS SDK?

A:

Fundamentally, the TFS clients (tfpt uu, for example) determine whether you've changed a checked-out file by comparing the hash of the local file against the hash of the server item at the version that you have in your workspace.  
To implement this behavior:

Compute the MD5 hash of the local file
Query the item on the server: workspace.VersionControlServer.GetItems(fileName, new WorkspaceVersionSpec(workspace), RecursionType.None)
Compare the Item's HashValue with the value computed in step 1.

