Question

I like to checkout a file trough C# code, but I always get a TF14098 Acess Denied Exception. The TFS Administrator reassures, that I have checkout/edit permissions and in VisualStudio and with tf.exe I do not have any problems to checkout the file.

This is my current C# code:

            const string tfsServer = @"http://MyServer:8080/tfs";
        const string fileName = @"$/MyFile.xaml";
        const string workspaceName = "MyWorkspace";

        using (TfsTeamProjectCollection tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(tfsServer)))        
        {               
            if (tfs != null)
            {
                WorkspaceInfo workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(fileName);
                if (null != workspaceInfo)
                {
                    var vcs = tfs.GetService<VersionControlServer>();   
                    Workspace workspace = workspaceInfo.GetWorkspace(tfs);                                  
                    if(workspace == null){

                        workspace = vcs.GetWorkspace(workspaceName, vcs.AuthorizedUser);
                    }                   

                    vcs.NonFatalError +=    VersionControlOnNonFatalError;
                    vcs.Getting += OnGetting;
                    vcs.BeforeCheckinPendingChange += OnBeforeCheckinPendingChange;
                    vcs.NewPendingChange += OnNewPendingChange;

                    if (workspace != null)
                    {
                        workspace.PendEdit(fileName);
                    }                       
                }
            }
        }

It results always with:

Non-fatal failure: TF14098: Access Denied: User Me needs PendChange permission(s) for $/MyFile.xaml.

After a lot of research for this error I tryed to check the permissions trough Dos-Box and I did the following commandline:

tf checkout $/MyFile.xaml

it results in a Checkout of the file without any problem! (If I am in the directory where the file resists)

Has anyone a Idea what the problem may be? What's the difference between my code (my Application written and executed with VisualStudio2012) and the commandline tf checkout?

Thanks for tips and hints! Patrik

Was it helpful?

Solution

The problem in your code is, that the TfsTeamProjectCollection does not fit to your path, because you never set the Collection name (should be something like @"http://MyServer:8080/tfs/DefaultCollection"). I never did a checkout by using the API, but I did a checkin starting like this:

WorkspaceInfo wi = Workstation.Current.GetLocalWorkspaceInfo(Environment.CurrentDirectory);
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(wi.ServerUri);

VersionControlServer versionControlServer = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
Workspace workSpace = versionControlServer.GetWorkspace(wi);

As you can see, I search the TeamCollection by using my workspace and not setting it independent. Doing it this way, you will get the right VersionControlServer to do your checkout.

The difference by using the tf.exe tool is, that you run it in your local workspace, so the tool knows to which item it is linked in TFS and to which Collection.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top