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();
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