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.
- Edited by Yotam.Comverse 22 hours 26 minutes ago