Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the URL of the WebAccess for a TFS Team Project programmatically

Tags:

tfs

tfs-sdk

I want to get the URL of the web access Page for a specific TeamProject.

I found some samples using a TswaClientHyperlinkService object calling GetHomeUrl(new Uri("MyprojectName")), but I was not able to provide a correct Uri value for that. Maybe I did not understand how to format the parameter..

I know how to get the base url for the webaccess, but I want to get to the page for a specific Team Project within a specifc Team Project Collection.

like image 725
ulfgebhardt Avatar asked Feb 18 '23 18:02

ulfgebhardt


1 Answers

It turns out that the GetHomeUrl method expects a vsts:// url, not the url to the project collection you'd normally use. The following code can be used to get the Uri:

 var server = TfsConfigurationServerFactory.GetConfigurationServer(new Uri("http://localhost:8080/tfs" /* your tfs uri here */));
 server.Authenticate();

 var service = server.GetService<TswaClientHyperlinkService>();
 var projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://localhost:8080/tfs/DefaultCollection"));
 var cssService = projectCollection.GetService<ICommonStructureService3>();
 var project = cssService.GetProjectFromName(/*YourProjectNameHere*/);

 var home = service.GetHomeUrl(new Uri(project.Uri));
like image 65
jessehouwing Avatar answered Feb 26 '23 12:02

jessehouwing