Retrieving the associated shared service provider's name?

梦想的初衷 提交于 2019-12-13 15:36:42

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/58809/retrieving-the-associated-shared-service-providers-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!