Check if the file is already in the source control

I work with TFS programmatically using classes from the Microsoft.TeamFoundation.VersionControl.Client namespace . My goal is to check files from a local folder into the source control. Some files may already exist in SC and need to be changed, some new and need to be added, some of them exist in SC and do not change, so I do not need to do anything with them.

My problem is that I cannot figure out how to check if a file exists in the source control, so I cannot decide in my code whether to add or edit it. None of the Workspace methods seem to do what I need.

The code I have is:

foreach (string file in fileList) { workspace.PendEdit(file); workspace.PendAdd(file); } 

He does the job, but looks stupid and slow. What is the right way to do this?

+8
c # tfs tfs-sdk
source share
1 answer

I don’t know about the β€œright” one, but in one of my tools I use VersionControlServer.ServerItemExists to get what you are after.

In your case, you will need to check something like this:

 versionControlServer.ServerItemExists(workspace.GetServerItemForLocalItem("filePath"), ItemType.Any) 
+10
source share

All Articles