SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Here when I am creating a new custom section it is showing an error as Adding a property definition requires Manage User Profiles rights in the code

CoreProperty cp = cpm.Create(true);

How can I solve this problem?

SPSite site = new SPSite("localhost");
SPServiceContext context = SPServiceContext.GetContext(site);
UserProfileConfigManager upcm = new UserProfileConfigManager(context);

ProfilePropertyManager ppm = upcm.ProfilePropertyManager;

CorePropertyManager cpm = ppm.GetCoreProperties();

if (cpm.GetSectionByName(propertyname) == null)
       **CoreProperty cp = cpm.Create(true);**
       cp.Name = propertyname;
       cp.DisplayName = displayname;

       ProfileTypePropertyManager ptpm = ppm.GetProfileTypeProperties(ProfileType.User);
       ProfileTypeProperty ptp = ptpm.Create(cp);

       ProfileSubtypeManager psm = ProfileSubtypeManager.Get(context);
       ProfileSubtype ps = psm.GetProfileSubtype(ProfileSubtypeManager.GetDefaultProfileName(ProfileType.User));

       ProfileSubtypePropertyManager pspm = ps.Properties;
       ProfileSubtypeProperty psp = pspm.Create(ptp);
share|improve this question

I think there is a pemission problem.

Run your code in elevated privileges, like this:

            SPSite site = properties.Feature.Parent as SPSite;
            SPUser AdminUser = sitefeature.RootWeb.AllUsers[@"SHAREPOINT\SYSTEM"];
            var superToken = AdminUser.UserToken;
            HttpContext con = HttpContext.Current;

                using (SPSite site = new SPSite(sitefeature.Url, superToken))
                   // create custom property code here

            HttpContext.Current = con;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.