/// <summary> /// Use this function is in a single call to SPO you want to set multiple profile properties. 1st item in propertyname array is associated to first item in propertvalue array etc /// </summary> /// <param name="UserName"></param> /// <param name="PropertyName"></param> /// <param name="PropertyValue"></param> static void SetMultipleProfileProperties(string UserName, string[] PropertyName, string[] PropertyValue) { LogMessage("Setting multiple SPO user profile properties for " + UserName, LogLevel.Information); try { int arrayCount = PropertyName.Count(); UPSvc.PropertyData[] data = new UPSvc.PropertyData[arrayCount]; for (int x = 0; x < arrayCount; x++) { data[x] = new UPSvc.PropertyData(); data[x].Name = PropertyName[x]; data[x].IsValueChanged = true; data[x].Values = new UPSvc.ValueData[1]; data[x].Values[0] = new UPSvc.ValueData(); data[x].Values[0].Value = PropertyValue[x]; } _userProfileService.ModifyUserPropertyByAccountName(UserName, data); //LogMessage("Finished setting multiple SPO user profile properties for " + UserName, LogLevel.Information); } catch (Exception ex) { LogMessage("User Error: Exception trying to update profile properties for user " + UserName + "\n" + ex.Message, LogLevel.Error); } }
/// <summary> /// Write a MultiValued property to SPO /// </summary> /// <param name="UserName"></param> /// <param name="PropertyName"></param> /// <param name="PropertyValue"></param> static void SetSingleMVProfileProperty(string UserName, string PropertyName, string PropertyValue) { try { string[] arrs = PropertyValue.Split(ConfigurationManager.AppSettings["PROPERTYSEPERATOR"][0]); UPSvc.ValueData[] vd = new UPSvc.ValueData[arrs.Count()]; for (int i = 0; i <= arrs.Count() - 1; i++) { vd[i] = new UPSvc.ValueData(); vd[i].Value = arrs[i]; } UPSvc.PropertyData[] data = new UPSvc.PropertyData[1]; data[0] = new UPSvc.PropertyData(); data[0].Name = PropertyName; data[0].IsValueChanged = true; data[0].Values = vd; _userProfileService.ModifyUserPropertyByAccountName(string.Format(@"i:0#.f|membership|{0}", UserName), data); } catch (Exception ex) { LogMessage("Exception trying to update profile property " + PropertyName + " for user " + UserName + "\n" + ex.Message, LogLevel.Error); } }
/// <summary> /// Use this function if you want to set a single property in the user profile store /// </summary> /// <param name="UserName"></param> /// <param name="PropertyName"></param> /// <param name="PropertyValue"></param> static void SetSingleProfileProperty(string UserName, string PropertyName, string PropertyValue) { try { UPSvc.PropertyData[] data = new UPSvc.PropertyData[1]; data[0] = new UPSvc.PropertyData(); data[0].Name = PropertyName; data[0].IsValueChanged = true; data[0].Values = new UPSvc.ValueData[1]; data[0].Values[0] = new UPSvc.ValueData(); data[0].Values[0].Value = PropertyValue; _userProfileService.ModifyUserPropertyByAccountName(UserName, data); } catch (Exception ex) { LogMessage("Exception trying to update profile property " + PropertyName + " for user " + UserName + "\n" + ex.Message, LogLevel.Error); } }