UserProfile class
SharePoint 2013
Represents a user profile for a person in the user profile database.
System.Object
Microsoft.Office.Server.UserProfiles.ProfileBase
Microsoft.Office.Server.UserProfiles.UserProfile
Microsoft.Office.Server.UserProfiles.ProfileBase
Microsoft.Office.Server.UserProfiles.UserProfile
Assembly: Microsoft.Office.Server.UserProfiles (in Microsoft.Office.Server.UserProfiles.dll)
The Commit method must be called whenever a property of this class is changed or all changes will be lost.
The following code example shows the use of the UserProfile class.
public void UserProfileSample() { // Get SPSite and service context from string strUrl = "http://SampleName"; SPSite site = new SPSite(strUrl); SPServiceContext serviceContext = SPServiceContext.GetContext(site); // Initialize user profile config manager object UserProfileManager upm = new UserProfileManager(serviceContext); //Create user sample string sAccount = "mydomain\\myalias"; if (!upm.UserExists(sAccount)) upm.CreateUserProfile(sAccount); //To set prop values on user profile UserProfile u = upm.GetUserProfile(sAccount); string sPropName = "PreferredName"; u[sPropName] = sAccount; u.Commit(); //remove user profile sample upm.RemoveUserProfile(sAccount); } public void CreatePersonalSiteSample() { // Get SPSite and service context from string strUrl = "http://SampleName"; SPSite site = new SPSite(strUrl); SPServiceContext serviceContext = SPServiceContext.GetContext(site); // Initialize user profile config manager object UserProfileManager upm = new UserProfileManager(serviceContext); string sAccount = "mydomain\\myalias"; UserProfile u = upm.GetUserProfile(sAccount); u.CreatePersonalSite(); SPSite mysite = u.PersonalSite; string myurl = u.PersonalUrl; }