sharepointmosssharedservicesprovider

Retrieving the associated shared service provider's name?


How do you programmatically retrieve the name of a shared services provider that's associated with a specific Sharepoint web application?

I have a custom solution that needs to:

  1. Enumerate all web applications that it's deployed to
  2. Figure out the Shared Services provider that each of the web applications is associated with
  3. Access a Business Data Catalog installed on the SSP to retrieve some data
  4. Enumerate through all site collections in those web applications
  5. Perform various tasks within the site collections according to the data

I got points 1, 3, 4 and 5 figured out, but 2 is somewhat troublesome. I want to avoid hardcoding the SSP name anywhere and not require the farm administrator to manually edit a configuration file. All information I need is in the Sharepoint configuration database, I just need to know how to access it through the object model.


Solution

  • Unfortunately there is no supported way I know of that this can be done. The relevant class is SharedResourceProvider in the Microsoft.Office.Server.Administration namespace, in the Microsoft.Office.Server DLL. It's marked internal so pre-reflection:

    SharedResourceProvider sharedResourceProvider = ServerContext.GetContext(SPContext.Current.Site).SharedResourceProvider;
    string sspName = sharedResourceProvider.Name;
    

    Post-reflection:

    ServerContext sc = ServerContext.GetContext(SPContext.Current.Site);
    PropertyInfo srpProp = sc.GetType().GetProperty(
        "SharedResourceProvider", BindingFlags.NonPublic | BindingFlags.Instance);
    object srp = srpProp.GetValue(sc, null);
    PropertyInfo srpNameProp = srp.GetType().GetProperty(
        "Name", BindingFlags.Public | BindingFlags.Instance);
    string sspName = (string)srpNameProp.GetValue(srp, null);
    

    An alternative would be to write a SQL query over the configuration database which isn't recommended.