I am writing a WebMethod in an Application Page for a SharePoint 2010 site, that updates the current user's profile properties.
Web Method:
[WebMethod]
public static string setProfileProperties(ProfileProperties data)
{
if (data == null)
{
return "{\"result\": \"" + false + "\"}";
}
SPSite site = SPContext.Current.Site;
SPWeb web = SPContext.Current.Web;
SPServiceContext context = SPServiceContext.GetContext(site);
UserProfileManager upm = new UserProfileManager(context);
string loginName = web.CurrentUser.LoginName;
if (upm.UserExists(loginName))
{
UserProfile profile = upm.GetUserProfile(loginName);
profile[PropertyConstants.WorkEmail].Value = data.email;
profile[PropertyConstants.FirstName].Value = data.name;
profile.Commit(); // error here!!
return "{\"result\": \"" + true + "\"}";
}
return "{\"result\": \"" + false + "\"}";
}
NOTE: ProfileProperties
is a custom object with fields such as name
and email
.
The data being passed in is already correct, yet when I commit the changes, I get a 500 server error. My assumption is permissions. Does anyone know how I can get my profile to save/commit changes? Thanks.
domain\user