4

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.

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
ulfgebhardt
  • 125
  • 1
  • 8
  • @jessehouwing Thanks for your answer, I have had the same idea, but id did not work for me. It causes an "Argument Exception: Malformed Artifact URI:https://mytfs/tfs/collection/project ". The URI is correct, so I do not get the idea. – ulfgebhardt Jan 22 '13 at 13:36
  • Yes, the uri is complete and valid – ulfgebhardt Jan 22 '13 at 14:08
  • Do you want to get the URL of the TeamProject site in SharePoint (`http://yourtfs:8080/tfs/ProjectCollection/Project`) or in WebAccess (e.g. `http://tfs:8080/tfs/web/Index.aspx?puri=vstfs%3A%2F%2F%2FClassification%2FTeamProject%2Fa33f88ab-839c-4ece-99e4-7fac491daed7`)? I expect that you are working with the API of TFS2010, right? – MikeR Jan 22 '13 at 14:23
  • I need the WebAccess Url not the sharepoint, and yes, I'm working with TFS2010 API – ulfgebhardt Jan 22 '13 at 14:48

1 Answers1

8

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));
jessehouwing
  • 106,458
  • 22
  • 256
  • 341
  • 1
    Great answer, that works fine for me except for one little detail: For TFS2010 the interface ICommonStructureService4 is not available, it is for TFS2012. But ICommonStructureService3 works fine with TFS2012 – ulfgebhardt Jan 23 '13 at 10:49