Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm trying to update my user profile programmatically, but I get an error saying only an administrator can update that field. I am the administrator on my laptop, where I am running SharePoint on Windows 7. Can someone tell me how I can get SharePoint to know that I am the administrator so I can update my and other profiles? I've checked SharePoint and I'm listed as the owner of the site. Also, if there is a way to update these things in the interface, I'd be glad to do that instead of code.

using (SPSite site = new SPSite(SPContext.Current.Web.Url))
{
    using (SPWeb web = site.OpenWeb())
    {
        web.AllowUnsafeUpdates = true;
        SPServiceContext context = SPServiceContext.GetContext(site);
        UserProfileManager profileManager = new UserProfileManager(context);
        string sAccount = "Wanna\\be";
        UserProfile u = profileManager.GetUserProfile(sAccount);
        u[PropertyConstants.HomePhone].Value = "9999999999";
        u[PropertyConstants.CellPhone].Value = "9999999999";
        u[PropertyConstants.FirstName].Value = "Wanna";
        u[PropertyConstants.LastName].Value = "Be";
        u[PropertyConstants.WorkEmail].Value = "wannabe@mycompany.com";
        u.Commit();
    }
}
share|improve this question

1 Answer 1

Try running your code using RunWithElevatedPrevilges SPSecurity.RunWithElevatedPrivileges(delegate() { // Implement code here });

share|improve this answer
    
I added the RunWithElevatedPrivileges and am still not able to edit the profile of a user. I get the error: Property Not Editable: This property can only be modified by an administrator. How can I fix this? The error shows when modifying the first or last name and when trying to commit it. –  Mike Collins Sep 12 '12 at 14:38

Your Answer

 
discard

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.