UserProfile class

Represents a user profile for a person in the user profile database.

Inheritance hierarchy

System.Object
  Microsoft.Office.Server.UserProfiles.ProfileBase
    Microsoft.Office.Server.UserProfiles.UserProfile

Namespace:  Microsoft.Office.Server.UserProfiles
Assembly:  Microsoft.Office.Server.UserProfiles (in Microsoft.Office.Server.UserProfiles.dll)

Syntax

'Declaration
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel := True)> _
Public Class UserProfile _
    Inherits ProfileBase
'Usage
Dim instance As UserProfile
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
public class UserProfile : ProfileBase

Remarks

The Commit method must be called whenever a property of this class is changed or all changes will be lost.

Examples

The following code example shows the use of the UserProfile class.

Public Sub UserProfileSample() 
' Get SPSite and service Context         
Dim strUrl As String = "http://SampleName"          
Dim site as SPSite = new SPSite(strUrl)          
Dim serviceContext as SPServiceContext = SPServiceContext.GetContext(site)          'initialize user profile manager object          
Dim upm As New UserProfileManager(serviceContext)          
'Create user sample          
Dim sAccount As String = "mydomain\myalias"          
If Not upm.UserExists(sAccount) Then             upm.CreateUserProfile(sAccount)          
End If          
'To set prop values on user profile          
Dim u As UserProfile = upm.GetUserProfile(sAccount)          
Dim sPropName As String = "PreferredName"          
u(sPropName) = sAccount          
u.Commit()           
'Remove user profile sample          
upm.RemoveUserProfile(sAccount)       
End Sub 'UserProfileSample         
Public Sub CreatePersonalSiteSample()          
' Get SPSite and service Context         
Dim strUrl As String = "http://SampleName"          
Dim site as SPSite = new SPSite(strUrl)          
Dim serviceContext as SPServiceContext = SPServiceContext.GetContext(site)          'initialize user profile manager object          
Dim upm As New UserProfileManager(serviceContext)          
Dim sAccount As String = "mydomain\myalias"          
Dim u As UserProfile = upm.GetUserProfile(sAccount)          u.CreatePersonalSite()          
Dim mysite As SPSite = u.PersonalSite          
Dim myurl As String = u.PersonalUrl       
End Sub 
'CreatePersonalSiteSample
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; }

Thread safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See also

Reference

UserProfile members

Microsoft.Office.Server.UserProfiles namespace