UserProfile Class

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

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

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

[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
public class UserProfile

The following code examples show how to use the UserProfile class to create a user profile and personal site.

public void UserProfileSample() 
{ 
   //get portal site context from topology string 
   strUrl = "http://SampleName"; 
   TopologyManager tm = new TopologyManager(); 
   PortalSite ps = tm.PortalSites[new Uri(strUrl)]; 
   PortalContext pc = PortalApplication.GetContext(ps);  

   //initialize user profile config manager 
   object UserProfileManager upm = new UserProfileManager(pc); 

   //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 portal site context from topology 
   string strUrl = "http://SampleName"; 
   TopologyManager tm = new TopologyManager(); 
   PortalSite ps = tm.PortalSites[new Uri(strUrl)]; 
   PortalContext pc = PortalApplication.GetContext(ps);  
   //initialize user profile config manager object 
   UserProfileManager upm = new UserProfileManager(pc); 
   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.

Community Additions

ADD
Show: