Download presentation
Presentation is loading. Please wait.
Published byHengki Muljana Modified over 5 years ago
1
Developing SharePoint Server Advanced Solutions
Developing SharePoint Server Advanced Solutions Managing and Accessing User Profile Data
2
Managing and Accessing User Profile Data Overview
User Profiles in SharePoint 2013 Adding People Search Functionality to an App Displaying User Profile Properties
3
Demonstration: Reviewing the Default User Profile Properties
In this demonstration, you will see an overview of the default user profile properties, data type and default privacy settings. You will also review the Active Directory connection configuration settings.
4
Understanding Options for Accessing User Profile Data
Searching for Users
5
Development Options for Managing User Profile Data
Read/Write Server-side object model Read only .NET client-side object model REST JavaScript object model Exceptions Profile picture can be changed from client-side code PeopleManager.setMyProfilePicture
6
All users with profiles
Enumerating Users Site users All users with profiles Consider Search var users = SPContext.Current.Site.RootWeb.AllUsers; foreach (var user in users) { } var context = SPServiceContext.Current; var userProfileManager = new UserProfileManager(context); var users = userProfileManager.GetEnumerator(); while (users.MoveNext()) { }
7
Use Keyword Query Language
Searching for Users Use Keyword Query Language Specify the Local People Results result source ID: b09a ea-4af9-81ef-edfab16c4e31 var query = new Microsoft.SharePoint.Client.Search.Query.KeywordQuery (clientContext); query.set_queryText("FirstName:" + firstName); query.set_sourceId ("B09A EA-4AF9-81EF-EDFAB16C4E31"); clientContext.executeQueryAsync(function () { … });
8
Demonstration: People Search in an App
9
Managing User Profile Data
Discussion: Accessing User Profile Data with Client-side Code
10
Creating User Profiles
Reference assemblies: Microsoft.Office.Server Microsoft.Office.Server.UserProfiles Include Microsoft.Office.Server.UserProfiles namespace SPServiceContext serviceContext = SPServiceContext.Current; UserProfileManager = new UserProfileManager(serviceContext); UserProfile userProfile = userProfileManager.CreateUserProfile("CONTOSO\Mike");
11
Retrieving User Profile Properties by Using Client-side Code
var properties = ["AccountName“, “FirstName“]; var username = "CONTOSO\Mike"; var peopleManager = new SP.UserProfiles.PeopleManager(clientContext); var profilePropertiesRequest = new SP.UserProfiles.UserProfileProeprtiesForUser (clientContext, username, properties); var profileProperties = peopleManager.getUserProfilePropertiesFor (profilePropertiesRequest); clientContext.load(profilePropertiesRequest); clientContext.executeQueryAsync(function () { accountName = profileProperties[1]; // Process success. }, function() { // Process failure. });
12
Retrieving User Profile Properties by Using Server-side Code
UserProfile user = … ; // Assume a valid UserProfile instance. // Properties for common profile properties. var accountName = user.AccountName; // Indexer for any properties. var accountName = user["AccountName"].Value; // PropertyConstants enumeration to simplify development. var accountName = user[PropertyConstants.AccountName].Value; // Enumerator or index for multi-value profile properties. var values = user[PropertyConstants.AccountName].GetEnumerator(); var value1 = user[PropertyConstants.AccountName][0];
13
Updating User Profile Properties
Update any property in server-side code Cannot update a property on a GET request Override by using the SPWeb.AllowUnsafeUpdates property Update the profile picture in client-side code PeopleManager.setMyProfilePicture UserProfile user = … ; // Assume a valid UserProfile instance. // Common profile properties. userProfile.DisplayName = "Display Name"; // Any profile property. userProfile["FirstName"].Value = "First Name" // Persist changes. useProfile.Commit();
14
Demonstration: User Profile Properties, Client Side Code
15
References MSDN: Work with user profile data
us/library/jj aspx
16
References How to: Work with user profiles and organization profiles by using the server object model in SharePoint 2013 nkId=321952 us/library/jj aspx
17
Microsoft Press Books SharePoint 2013 Inside Out
Chapter 6 Inside SharePoint 2013 Chapter 17
18
Module Review and Takeaways
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.