Tuesday, 17 May 2011

Creating User profile in SharePoint 2007 using object in form authentication


string accountName = string.Empty;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
// Create the user profile object
Microsoft.Office.Server.UserProfiles.UserProfile currentUserProfile = null;
// Creating spsite object
SPSite sc = new SPSite("http://webserverurl");
// Get the server context
Microsoft.Office.Server.ServerContext context = Microsoft.Office.Server.ServerContext.GetContext(sc);
// Get the user profile manager object               
Microsoft.Office.Server.UserProfiles.UserProfileManager profileManager1 = new Microsoft.Office.Server.UserProfiles.UserProfileManager(context);
// Check if the user exists
if (!profileManager1.UserExists(accountName))
{
// Create user profile
currentUserProfile = profileManager1.CreateUserProfile(accountName);
}
});