I am working with TFS programmatically using classes from Microsoft.TeamFoundation.VersionControl.Client namespace. My goal is to check-in files from the local folder into source control. Some files may already exist in SC and should be Edited, some are new and should be added, some exist in SC and haven't changed, so I don't need to do anything with them.
My problem is that I can't figure out how to check whether a file already exists in source control, so I can't decide in my code whether I should Add or Edit it. None of the Workspace methods seem to do what I need.
The code I have:
foreach (string file in fileList)
{
workspace.PendEdit(file);
workspace.PendAdd(file);
}
It does the job, but it looks dumb and feels slow. What is the correct way to do it?
I don't know about 'correct', but in one of my tools I make use of VersionControlServer.ServerItemExists in order to get what you 're after.
In your case you would have to check with something like this:
versionControlServer.ServerItemExists(workspace.GetServerItemForLocalItem("filePath"), ItemType.Any)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With