I want to auto create project environment by my web application. But sometimes it couldn't get the pending changes and cause the exception:
The array must contain at least one element. Parameter name: checkinParameters.PendingChanges
My code is:
Workspace workspace = m_TfsVersionControlServer.GetWorkspace(System.Environment.MachineName, System.Environment.UserName);
int iSuccess = workspace.PendAdd(localPath, true);
PendingChange pendingChanges = workspace.GetPendingChanges(localPath, RecursionType.Full);
The array "pendingChanges" is empty. The user account has administrator permissions and the serverPath and localPath is correctly. Why I couldn't get the pending changes every time? Something wrong with my code or workspace settings?
The most likely thing is that the items already exist in the repository. You can only add something once. PendAdd will return the number of items which it pended an add on. Is iSuccess equal to zero? If so, then you should not try to check in, because there are no pending changes because PendAdd did not create any.
Yes, the PendAdd didn't create anything. The "localPath" I've given in PendAdd as the first parameter is the path at the end of team project node. I add folders under this node and I give another parameter "true" means recurse through subitems. The added folders under the" localPath" will add to pending changeset but it dosen't work. When I change the path to the first new folder then all the folders can be created in pending changeset. And if only one folder added under the "localPath", so "workspace.PendAdd(localPath, true)" works well. It's so odd. I think PendAdd can find all the items under the "localPath" but is not. Shouldn't I give the top level path for add all of th subitems?