1 out of 1 rated this helpful - Rate this topic

UserProfile Class

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

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)
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
public class UserProfile : ProfileBase

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; }
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
User Profile Properties

You must use the UserProfileConfigManager class object instead of the UserProfileManager object to manage metadata. Please refer to :http://msdn.microsoft.com/en-us/library/microsoft.office.server.userprofiles.userprofileconfigmanager.aspx

 

Using SPQuery for UserProfiles
I developed a birthday webpart that displays user's with a birthday by querying the upm. When i deployed the wp on a farm of over 5000 users in the user profiles, i experienced some delay. $0$0 $0 $0So am i thinking of using the spquery, which is the fastest way to get data in SP. How can i use spquery with upm?$0
UserProfile

UserProfile user = upm.GetUserProfile(username);
user.GetProfileValueCollection(propertyName).Value = value;
user.Commit();
Property or indexer 'Microsoft.Office.Server.UserProfiles.UserProfile.this[string]' cannot be assign

I user SharePoint 2010: When I try to update the Profile information as described, I receive the following compiler error:
Property or indexer 'Microsoft.Office.Server.UserProfiles.UserProfile.this[string]' cannot be assigned to -- it is read only

Plse help

Thanks
Mehdi