How to: Create and Edit a Organization Profile Property?
Maintaining Organization Profile in SharePoint profile store is a new feature of SharePoint 2010. Original sample of creating/editing user profile property can be found here. Here is a sample to create/edit a org profile property.
// Code example adds a new organization property called Industry Focus
using (SPSite site = new SPSite("https://servername"))
{
SPServiceContext context = SPServiceContext.GetContext(site);
UserProfileConfigManager upcm = new UserProfileConfigManager(context);
try
{
ProfilePropertyManager ppm = upcm.ProfilePropertyManager;
// create core property
CorePropertyManager cpm = ppm.GetCoreProperties();
CoreProperty cp = cpm.Create(false);
cp.Name = "IndustryFocus";
cp.DisplayName = "Industry Focus";
cp.Type = "String (Single Value)";
cp.Length = 100;
cpm.Add(cp);
// create profile type property
ProfileTypePropertyManager ptpm = ppm.GetProfileTypeProperties(ProfileType.Organization);
ProfileTypeProperty ptp = ptpm.Create(cp);
ptpm.Add(ptp);
// create profile subtype property
ProfileSubtypeManager psm = ProfileSubtypeManager.Get(context);
ProfileSubtype ps = psm.GetProfileSubtype(ProfileSubtypeManager.GetDefaultProfileName(ProfileType.Organization));
ProfileSubtypePropertyManager pspm = ps.Properties;
ProfileSubtypeProperty psp = pspm.Create(ptp);
psp.PrivacyPolicy = PrivacyPolicy.OptIn;
psp.DefaultPrivacy = Privacy.Organization;
pspm.Add(psp);
}
catch (DuplicateEntryException e)
{
Console.WriteLine(e.Message);
Console.Read();
}
catch (System.Exception e2)
{
Console.WriteLine(e2.Message);
Console.Read();
}
}