1.通过Jsom获取用户属性
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js"></script>
<script type="text/javascript" src="/_layouts/15/SP.UserProfiles.js"></script>
var currentUser,ctx,oweb,personProperties; function getUserpropery() { ctx = new SP.ClientContext.get_current(); oweb=ctx.get_web(); currentUser=oweb.ensureUser("[email protected]"); ctx.load(currentUser); ctx.executeQueryAsync(onRequestSuccess,onRequestFail); } function onRequestSuccess() { var loginName=currentUser.get_loginName(); console.log(loginName); var peopleManager = new SP.UserProfiles.PeopleManager(ctx); personProperties = peopleManager.getPropertiesFor(loginName); //获取指定用户
//personProperties = peopleManager.getMyProperties(); 获取当前登录用户 clientContext.load(personProperties); clientContext.executeQueryAsync(function() { console.log(personProperties.get_userProfileProperties()["Manager"]); },function(){}); } function onRequestFail(sender, args) { console.log(args.get_message()); }
2.通过Csom获取用户属性
需要引用
Microsoft.SharePoint.Client
Microsoft.SharePoint.ClientRuntime
Microsoft.SharePoint.Client.UserProfiles
using Microsoft.SharePoint.Client; using Microsoft.SharePoint.Client.UserProfiles; namespace UserProfilesCSOM { class Program { static void Main(string[] args) { const string serverUrl = "http://serverName/"; const string targetUser = "domainName\\\\userName"; ClientContext clientContext = new ClientContext(serverUrl); PeopleManager peopleManager = new PeopleManager(clientContext); PersonProperties personProperties = peopleManager.GetPropertiesFor(targetUser); clientContext.Load(personProperties, p => p.AccountName, p => p.UserProfileProperties); clientContext.ExecuteQuery(); foreach (var property in personProperties.UserProfileProperties) { Console.WriteLine(string.Format("{0}: {1}", property.Key.ToString(), property.Value.ToString())); } Console.ReadKey(false); } } }