Programatically checking files into TFS getting more than expected

Christopher Klein picture Christopher Klein · Mar 26, 2009 · Viewed 9.7k times · Source


So I have a .NET app which goes thru and generates a series of files, outputs them to a local directory and then determines if it needs to update an existing file or add a new file into a TFS (Team Foundation Server) project.
I have a single workspace on my local machine and there are 10 different working folders that are other coding projects I have worked on from this particular machine. My problem happens when I go to check if the file already exists in the TFS project and an update is required or if needs to be added to the project as a new file.
snipet:

static string TFSProject = @"$/SQLScripts/";
static WorkspaceInfo wsInfo;
static VersionControlServer versionControl;
static string argPath = "E:\\SQLScripts\\";

wsInfo = Workstation.Current.GetLocalWorkspaceInfo(argPath);
TeamFoundationServer tfs = new TeamFoundationServer(wsInfo.ServerUri.AbsoluteUri);
versionControl = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

Workspace workspace = versionControl.GetWorkspace(wsInfo);
workspace.GetLocalItemForServerItem(TFSProject);


At this point I check if the file exists and I do one of two things. if the file exists, then I mark the file for EDIT and then I writeout the file to the local directory, otherwise I will script the file first and then ADD the file to the workspace. I dont care if the physical file is identical to the one I am generating as I am doing this as a SAS70 requirement to 'track changes'

If it exists I do:
workspace.PendEdit(filename,RecurisionType.Full);
scriptoutthefile(filename);

or if it doesn't exist
scriptoutthefilename(filename);
workspace.PendAdd(filename,true);

Ok, all of that to get to the problem. When I go to check on pending changes against the PROJECT I get all the pending changes for all of the projects I have on my local machine in the workspace.

// Show our pending changes. 
PendingChange[] pendingChanges = workspace.GetPendingChanges();
foreach (PendingChange pendingChange in pendingChanges)
{
    dosomething...
}

I thought that by setting the workspace to workspace.GetLocalItemForServerItem(TFSProject) that it would give me ONLY the objects for that particular working folder.

If there any way to force the workspace object to only deal with a particular working folder?

Did that make any sense? Thanks in advance...

Answer

Ravi Eswaramoorthy picture Ravi Eswaramoorthy · Aug 10, 2010

using LINQ you can get the pending changes of particular folder

PendingChange[] pendingChanges = workspace
    .GetPendingChanges()
    .Where(x => x.LocalOrServerFolder.Contains(argPath))
    .ToArray();