Search code examples
c#tfspermissionsworkspace

C#, TFS, HasAdministerPermission is false on my PC with not-me TFS credentials


I am writing a C# app which downloads (using Microsoft.TeamFoundation) files from TFS to a workspace, manipulates the files, checks them in and deletes the workspace. The user never needs to know that the files were temporarily on their PC.

The user doesn't have access to the specific area of TFC but the network credentials built in to the app do.

So I get the workspace, like this

this.workspace = this.GetWorkspace(workspaceName, credentials);
this.workspace.Map(this.ProjectPath, workspaceFolder);
this.workspace.Get();

Where GetWorkspace is

private Workspace GetWorkspace(string workSpaceName, ICredentials credentials)
 {    
 var tpc = new TfsTeamProjectCollection(new Uri(this.Url), credentials);

 var versionControl = tpc.GetService<VersionControlServer>();

 var ws = versionControl.TryGetWorkspace(this.WorkspaceFolder)
 ?? versionControl.CreateWorkspace(workSpaceName, versionControl.AuthorizedUser);

 return ws;
}

Everything works up to the workspace.Get when I get TF204017: The operation cannot be completed because the user (ReadyAPI Test Runner) does not have one or more required permissions (Administer) for workspace MyWorkspace;username. Sure enough when I step through and check the permissions for the workspace variable the HasAdministerPermission is false.

My assumption is that the credential (Test Runner) does not have rights to my local folder (EffectivePermissions = "Read").

I have tried making the workspace public; and tried changing the workspace owner name but these don't seem to work. I even tried making the parent folder (to the workspace that's created and deleted) shared with the "Test Runner" credentials.

How can I make my parsed credentials have full rights to read write and delete?


Solution

  • You can download files from TFS without local workspace.

    You will need two things: tfs server name and file server name

    string tfsServerName ="yourServerName";
    string fileServerName ="yourFileServerName";
    

    now connect to server:

    TfsTeamProjectCollection tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(tfsServerName));
    tpc.EnsureAuthenticated();
    VersionControlServer sourceControl = (VersionControlServer)tpc.GetService(typeof(VersionControlServer));
    

    and now final line:

    sourceControl.DownloadFile(fileServerName, "your local path with file name and extension" );
    

    So above are basics.