从Central Admin获取用户配置文件属性-SharePoint 2013 Provider托管应用 [英] Fetching user profile properties from Central Admin - SharePoint 2013 Provider Hosted App
问题描述
我们有目前不支持的人员选择器控件.
We have people picker control which is currently not supported.
因此,我们正在尝试一种方法,其中将有一个文本框并选中名称按钮.单击支票名称"按钮后,我们通过使用CSOM从Central Admin获取用户配置文件属性来解析文本框中的用户名.
So, we are trying with an approach where we will have a text box and check names button. On click of check names button, we resolve user name in text box by fetching user profile properties from Central Admin using CSOM.
这是代码-
////字符串变量,用于存储siteURL
字符串 siteURL =" ; 跨度>
string siteURL = "Central Amin URL";
////字符串变量,用于存储要为其获取用户配置文件属性的用户的帐户名
//// String Variable to store the account name of the user for whom to get the user profile property
字符串 accountName =" 帐户名称"
string accountName = "Account Name";
////用于存储用户配置文件属性的字符串变量
//// String Variable to store the user profile property
字符串 userProfileProperty = "WorkPhone"
string userProfileProperty = "WorkPhone";
////获取SharePoint网站的上下文以访问数据
//// To get the context of the SharePoint site to access the data
ClientContext 新 ClientContext
ClientContext clientContext = new ClientContext(siteURL);
////在客户端上下文中传递凭据
clientContext.Credentials =新的NetworkCredential(用户名,密码,域);
clientContext.Credentials = new NetworkCredential(username, password, domain);
/////PeopleManager类提供了与人有关的操作方法
//// PeopleManager class provides the methods for operations related to people
PeopleManager 新 PeopleManager
PeopleManager peopleManager = new PeopleManager(clientContext);
////GetUserProfilePropertyFor方法用于获取用户的特定用户配置文件属性
//// GetUserProfilePropertyFor method is used to get a specific user profile property for a user
ClientResult 字符串
ClientResult<string> profileProperty = peopleManager.GetUserProfilePropertyFor(accountName, userProfileProperty);
clientContext.ExecuteQuery();
////显示用户的用户个人资料属性值
//// Display the user profile property value for the user
控制台 &"; WorkPhone:"
Console.WriteLine("WorkPhone: " + profileProperty.Value);
控制台
Console.ReadLine();
当我们遇到未经授权的错误/或建议任何最佳方法时,能否让我知道将用户名,密码和域传递到客户端上下文的一种好方法.
Can you let me know if it is a good approach to pass username, password and domain to client context as we are getting unauthorized error / or suggest any best approach.
此致,
Divya
Regards,
Divya
推荐答案
您好,
我建议您遵循以下指南在SharePoint加载项中使用人员选择器.
不建议在解决方案中使用硬代码".
这篇关于从Central Admin获取用户配置文件属性-SharePoint 2013 Provider托管应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!