понедельник, 30 января 2012 г.

Получение Руководителя через UserProfile

SPSite oSite = new SPSite("nameSite");
SPWeb oWeb = oSite.OpenWeb();
SPUser oUser = oWeb.CurrentUs er();
SPServiceContext oSPServiceContext = SPServiceContext.GetContext(oSite);
UserProfileManager oUserProfileManager = new UserProfileManager(oSPServiceContext);
UserProfile oUserProfile = oUserProfileManager.GetUserProfile(oUser.ID);

UserProfile[] users = oUserProfile.GetManagers();
SPUser Manager =
oWeb.AllUsers[oUserProfile[PropertyConstants.Manager].ToString()];

//Теперь в Manager хранится руководитель oUser

2 комментария:

  1. Спасибо) но последние три строчки непонятны. У пользователя может быть несколько руководителей(по иерархии) и последний операнд делает выборку непосредственного руководителя?

    ОтветитьУдалить
  2. Да, это для получения непосредственного руководителя.

    ОтветитьУдалить