programmatically Create User Profiles sharepoint 2010

The example shows you how to Create User Profiles and Organization Profiles programmatically in SharePoint 2010.


Creating user Profiles -

SPServiceContext context = SPServiceContext.GetContext(site);


UserProfileManager upm = new UserProfileManager(context);

// create a user profile and set properties
UserProfile profile = upm.CreateUserProfile("domain\\isha");

profile.DisplayName = "Isha Attlee";

profile.Commit();

Creating organization profile -

SPServiceContext context = SPServiceContext.GetContext(site);

ProfileSubtypeManager psm = ProfileSubtypeManager.Get(context);

// choose default organization profile subtype as the subtype
string subtypeName = ProfileSubtypeManager.GetDefaultProfileName(ProfileType.Organization);

ProfileSubtype subType = psm.GetProfileSubtype(subtypeName);

OrganizationProfileManager opm = new OrganizationProfileManager(context);

// choose Root Organization as the parent

OrganizationProfile parentOrg = opm.RootOrganization;

// create an organization profile and set its display name

OrganizationProfile profile = opm.CreateOrganizationProfile(subType, parentOrg);

profile.DisplayName = "Test Org1";

// commit to save changes

profile.Commit();

0 comments:

Post a Comment

Disclaimer

This is a personal weblog. The opinions expressed here represent my own and not those of my employer or anyone else. Should you have any questions or concerns please e-mail me at sharepointprogrammingblogger@gmail.com .

Copyright (c) 2010 @ myshaepointwork.blogspot.com. All rights are reserved.Do Not Copy.

@ Learning SharePoint.com