【问题标题】:Error while updating pictureurl property of Sharepoint userprofile更新 Sharepoint 用户配置文件的图片 URL 属性时出错
【发布时间】:2016-02-01 17:26:43
【问题描述】:
【问题讨论】:
标签:
wcf
sharepoint
sharepoint-2013
【解决方案1】:
我在尝试更新用户配置文件属性时遇到了同样的错误,该代码对我有用:
SPUserToken token = SPUserToken.SystemAccount;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(currGuid, token))
{
site.AllowUnsafeUpdates = true;
HttpContext.Current = null; //clear the context for impersonation with token! mandatory!
SPServiceContext serviceContext = SPServiceContext.GetContext(site);
UserProfileManager profileManager = new UserProfileManager(serviceContext);
UserProfile prof = profileManager.GetUserProfile(userName);
prof["My Property"].Value = "abcd";
}
});
修复错误的部分是在获取配置文件管理器之前清除当前上下文。