Module 12 - SharePoint Practice

Download Report

Transcript Module 12 - SharePoint Practice

Microsoft
Course
MicrosoftOfficial
SharePoint
2013
®
Managing and Accessing User
Profile Data
SharePoint Practice
Module Overview
• Overview of User Profile Data in SharePoint 2013
• Understanding Options for Accessing User Profile
Data
• Managing User Profile Data
• Managing User Profile Properties
Lesson 1: Overview of User Profile Data in
SharePoint 2013
• Introducing User Profiles
• Property Data Sources
• Profile Properties and Data Protection
• Demonstration: Reviewing the Default User Profile
Properties
• SharePoint Configuration Requirements and
Considerations
Introducing User Profiles
• User Profiles
• Profile properties
• Data sources
• Profile subtypes
Property Data Sources
• Directory Services (for example Active Directory)
• User (stored in SharePoint)
• Business Connectivity Services (BCS)
Profile Properties and Data Protection
• Confidential data exposed by SharePoint
• Directory services
• Line-of-business applications
• Profile properties have default privacy setting
• Public
• Private
• User can override privacy setting
• Administrator can control this by configuring a policy
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.
SharePoint Configuration Requirements and
Considerations
• User Profile Service Application
• User Profile Service
• User Profile Synchronization Service
Lesson 2: Understanding Options for Accessing
User Profile Data
• Development Options for Managing User Profile
Data
• Enumerating Users
• Searching for Users
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
Enumerating Users
• Site users
var users = SPContext.Current.Site.RootWeb.AllUsers;
foreach (var user in users)
{}
• All users with profiles
var context = SPServiceContext.Current;
var userProfileManager = new UserProfileManager(context);
var users = userProfileManager.GetEnumerator();
while (users.MoveNext())
{}
• Consider Search
Searching for Users
• Use Keyword Query Language
• Specify the Local People Results result source
• ID: b09a7990-05ea-4af9-81ef-edfab16c4e31
var query = new
Microsoft.SharePoint.Client.Search.Query.KeywordQuery
(clientContext);
query.set_queryText("FirstName:" + firstName);
query.set_sourceId
("B09A7990-05EA-4AF9-81EF-EDFAB16C4E31");
clientContext.executeQueryAsync(function () { … });
Lesson 3: Managing User Profile Data
• Creating User Profiles
• Retrieving User Profile Properties by Using Client-
side Code
• Retrieving User Profile Properties by Using Serverside Code
• Updating User Profile Properties
• Discussion: Accessing User Profile Data with
Client-side Code
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");
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.
});
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];
Updating User Profile Properties
• Update any property in server-side code
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();
• 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
Discussion: Accessing User Profile Data with
Client-side Code
• In what scenarios might you use client-side code
to access user profile properties?
Lab A: Accessing User Profile Data
• Exercise 1: Add People Search Functionality to an App
• Exercise 2: Display User Properties in the App
Lab Scenario
The human resources team needs to view user
profiles for company employees. They must be
able to locate an employee profile quickly by
searching for the employee. They must be able to
search for users by account name, name, or by
specifying the user's department. Your task is to
add functionality to an app to provide the search
functionality by using client-side code.
Lesson 4: Managing User Profile Properties
• Managing User Profile Subtypes
• Adding User Profile Properties
• Updating User Profile Properties
• Deleting User Profile Properties
Managing User Profile Subtypes
ProfileSubtypeManager subTypeManager =
ProfileSubtypeManager.Get(SPServiceContext.Current);
ProfileSubtype newSubtype =
subtypeManager.CreateSubtype
("Name", "Display name", ProfileType.User);
subtypeManager.DeleteSubtype("Name");
ProfileSubType subtype =
subtypeManager.GetProfileSubtype("Name");
List<ProfileSubtype> profiles =
(List<ProfileSubtype>)subtypeManager.
GetSubtypesForProfileType(ProfileType.User);
Adding User Profile Properties
• ProfilePropertyManager class
• Core Property
• CorePropertyManager.Create method
• CoreProperty class
• Type Property
• ProfileTypePropertyManager.Create method
•
•
Specify ProfileType.User and core property
ProfileTypeProperty class
• Subtype Property
• ProfileSubtypePropertyManager.Create method
•
•
Specify subtype name and type property
ProfileSubtypeProperty class
Updating User Profile Properties
SPServiceContext context = SPServiceContext.Current;
// Obtain a reference to the UserProfileManager instance.
UserProfileManager uPM = new UserProfileManager(context);
// Obtain a reference to the ProfileSubtypePropertyManager
instance that represents the default profile subtype.
ProfileSubtypePropertyManager defaultPSPM =
upm.DefaultProfileSubtypeProperties;
// Obtain a reference to the property.
ProfileSubtypeProperty property =
defaultPSPM.GetPropertyByName(propertyName);
// Update the property.
// Call the Commit method to persist the changes to the
property
property.Commit();
Deleting User Profile Properties
ProfilePropertyManager propManager = …;
ProfileSubtypePropertyManager subtypePropManager =…;
subtypePropManager.RemovePropertyByName("Name");
propManager.Reset();
ProfileTypePropertyManager typePropManager = …;
typePropManager.RemovePropertyByName("Name");
CorePropertyManager corePropManager = …;
corePropManager.RemovePropertyByName("Name");
Lab B: Managing User Profile Properties
• Exercise 1: Add Code to Display User Profile
Properties
• Exercise 2: Add Code to Manage User Profile
Properties
Lab Scenario
The human resources team needs to add and
remove user profile properties in response to
business needs, for example to enable them to
track compliance with regulations, and to track
security clearance for specific projects. As
regulations change, or projects finish they will
remove the profile property to avoid a
proliferation of properties. In addition to the
ability to add and remove properties they need to
be able to control visibility of the properties. Your
task is to add code to a web part to display,
update, add, and delete user profile properties.
Module Review and Takeaways