CreateUserProfile access is denied (exception from HRESULT:0x80070005 (E_ACCESSDENIED)

Hi,

I'm using a wcf service that's suppose to add a user to AD and create a share point user profile. 

i'm getting the error in the CreateUserProfile method. any suggestion? 

this is my code:

public static bool CreateProfile(RegUserInformation UserData) { bool bSucceded = true; string siteUrlNli = Globals.SharePoint.SPConstants.SiteUrl; string siteUrl = SPContext.Current.Site.Url; try { SPSecurity.RunWithElevatedPrivileges(() => { using (Impersonator impersonator = new Impersonator()) { using (SPSite newsite = new SPSite(siteUrlNli)) using (SPSite site = new SPSite(siteUrl, newsite.RootWeb.AllUsers[Globals.ProfileSync.ClaimsWPrefix + Globals.ActiveDirectory.Domain + "\\" + Globals.ActiveDirectory.AdminUser].UserToken)) { site.AllowUnsafeUpdates = true; UserProfile up = null; IPrincipal principal = new GenericPrincipal(WindowsIdentity.GetCurrent(), new string[0]); HttpContext currentContext = HttpContext.Current;

HttpContext.Current.User = principal; SPServiceContext serviceContext = SPServiceContext.GetContext(site); UserProfileManager upm = new UserProfileManager(serviceContext, true); up = upm.CreateUserProfile(Globals.ProfileSync.ClaimsPrefix + UserData.UserName.Trim()); up.DisplayName = string.Format("{0} {1}", UserData.FName, UserData.LName); up[PropertyConstants.WorkEmail].Value = UserData.Email; up[PropertyConstants.FirstName].Value = UserData.FName; up[PropertyConstants.LastName].Value = UserData.LName; if (UserData.PersonalInfo != null) { up[PropertyConstants.CellPhone].Value = string.IsNullOrEmpty(UserData.PersonalInfo.Phone) ? "" : UserData.PersonalInfo.Phone; up["Institution"].Value = string.IsNullOrEmpty(UserData.PersonalInfo.Institution) ? "" : UserData.PersonalInfo.Institution; up["ResearchArea"].Value = string.IsNullOrEmpty(UserData.PersonalInfo.ResearchArea) ? "" : UserData.PersonalInfo.ResearchArea; up["ZipCode"].Value = string.IsNullOrEmpty(UserData.PersonalInfo.ZipCode) ? "" : UserData.PersonalInfo.ZipCode; up["HomeAddress"].Value = string.IsNullOrEmpty(UserData.PersonalInfo.Address) ? "" : UserData.PersonalInfo.Address; } up["SendEventsInfo"].Value = UserData.SendEventsInfo; if (UserData.Interests != null && UserData.Interests.Count > 0) { string strinterests = string.Join(",", UserData.Interests.ToArray()); up[PropertyConstants.Interests].Value = string.IsNullOrEmpty(strinterests) ? "" : strinterests; } up.Commit(); HttpContext.Current = currentContext; } } }); } catch (Exception ex) { Log.WriteToLog.WriteError(ex, "fallUpdatingUserProfile", Log.Categories.General); bSucceded = false; } return bSucceded;


Thanks in advance,

Yotam.


August 25th, 2015 5:17am

Hi Yotam,

It would be better to debug your code in Visual Studio and provide more details about the error message, others will be easier to research on this issue.

Anyway, here is a code demo about how to create user profiles by using the SharePoint 2013 server object model from MSDN, you can take it for a try in your environment:

https://msdn.microsoft.com/en-us/library/office/JJ163142.aspx?f=255&MSPPError=-2147217396#bkmk_CreateUP

Thanks                 

Patrick Liang

Free Windows Admin Tool Kit Click here and download it now
August 26th, 2015 1:07am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics