When creating some custom MySite code we wanted to link back to the searchcenter from my MySite but instead of using a webpart property we wanted to create our links the same way SharePoint does in the original MySite: with the “Preferred Search Center” location in the MySite Settings of your SSP. In the end it took me more time to find this property and a way to access it because it’s a non-public property so I thought it was worth a post seeing as I didn’t find anything else online for this.
//Get your current context (or the context of the SSP in question if that’s not the one your running in)
ServerContext current;
current = ServerContext.Current;
//Get the UserProfileApplication
object userProfileApplication = current.GetType().GetProperty("UserProfileApplication", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(current, null);
//Get the canonicalSearchCenterUrl
string preferredSearchCenterUrl = ((string)userProfileApplication.GetType().GetField("canonicalSearchCenterUrl", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(userProfileApplication));
Grtz,
Tom
Published: 9/22/2010 8:13 PM | 0 Comments | 0 Links to this post