2

Let's say we have a solution in TFS Source Control which has already been mapped to a local folder SolutionFolder.

We are in a sub folder SubFolder of this SolutionFolder. How can we write C# code to get the mapped path of this SubFolder?

Soner Gönül
  • 94,086
  • 102
  • 195
  • 339
Nam G VU
  • 30,868
  • 67
  • 216
  • 353

1 Answers1

5

Use the WorkStation.Current to grab the information for the folder in question:

Import the following namespaces:

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;

and then use you can get to the data you want through:

var workspace = Workstation.Current.GetLocalWorkspaceInfo(solutionFolder);
if (workspace != null)
{
    var teamProjectUri = workspace.ServerUri;

    // var server = TfsConfigurationServerFactory.GetConfigurationServer(teamProjectUri);
    var projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(teamProjectUri);   
    var cssService = projectCollection.GetService<ICommonStructureService4>();
    var project = cssService.GetProjectFromName(solutionName);
}

From there you can easily grab the Workspace as well and from there the serverpath: workspace.GetWorkspace().GetServerItemForLocalItem()

To provide credentials, you can use one of the additional overloads that accepts a CredentialsProvider. The default provider is the UICredentialsProvider. Or you can also call server or projectCollection's EnsureAuthenticated.

See also:

jessehouwing
  • 96,701
  • 20
  • 235
  • 310