2014-10-21 2 views
1

Sharepoint Online 2013에서 C#을 사용하여 사용자 프로필 속성을 업데이트하려고 시도했습니다. 어떻게 할 수 있습니까?Sharepoint Online 2013 (O365)에서 UserProfile 속성을 업데이트하는 방법

나는 사용자 프로필에 사용자 지정 속성을 많이 가지고 있고, 내가 제공자 호스팅 응용 프로그램에서 편집해야합니다 여기

내가해야 할 것입니다.

PersonProperties 및 PeopleManager를 사용하여 데이터를 가져오고 있습니다. 업데이트하는 방법은 무엇입니까?

감사합니다.

답변

0

This will probably be of some help

UserProfileService을 사용하여,이 클래스가 문제

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Net; 
using System.Security; 
using System.Text; 
using System.Threading.Tasks; 
using Microsoft.SharePoint.Client; 
using O365ProfileUpdate.UserProfileServiceRef; 

    public class O365Helper 
    { 
     private readonly UserProfileService _userProfileService; 
     private readonly Uri _targetAdminSite; 

     public O365Helper(UserProfileService userProfileService, Uri targetAdminSite, string adminUsername, 
          string adminPassword) 
     { 
      _userProfileService = userProfileService; 
      _targetAdminSite = targetAdminSite; 


      var authenticated = AuthenticateAdministrator(adminUsername, adminPassword); 

      if (!authenticated) 
       throw new UnauthorizedAccessException("Unable to authenticate administrator"); 
     } 

     public PropertyData GetProfileProperty(string login, string propertyName) 
     { 
      var memLogin = GetMembershipLogin(login); 

      return _userProfileService.GetUserPropertyByAccountName(memLogin, propertyName); 
     } 

     public bool UpdateProfileProperty(string login, string key, string value) 
     { 
      try 
      { 
       var valueData = new ValueData {Value = value}; 

       var newdata = new PropertyData[1]; 
       newdata[0] = new PropertyData {Name = key, Values = new ValueData[1]}; 
       newdata[0].Values[0] = valueData; 
       newdata[0].IsValueChanged = true; 

       var memLogin = GetMembershipLogin(login); 

       _userProfileService.ModifyUserPropertyByAccountName(memLogin, newdata); 
      } 
      catch 
      { 
       return false; 
      } 

      return true; 
     } 

     private bool AuthenticateAdministrator(string login, string password) 
     { 
      try 
      { 
       var securePassword = new SecureString(); 
       foreach (char c in password) 
       { 
        securePassword.AppendChar(c); 
       } 

       var onlineCredentials = new SharePointOnlineCredentials(login, securePassword); 

       string authCookieValue = onlineCredentials.GetAuthenticationCookie(_targetAdminSite); 
       var cookieVal = authCookieValue.TrimStart("SPOIDCRL=".ToCharArray()); 

       _userProfileService.CookieContainer = new CookieContainer(); 
       _userProfileService.CookieContainer.Add(new Cookie(
                  "FedAuth", 
                  cookieVal, 
                  String.Empty, 
                  _targetAdminSite.Authority)); 
      } 
      catch 
      { 
       return false; 
      } 

      return true; 
     } 

     private string GetMembershipLogin(string login) 
     { 
      return "i:0#.f|membership|" + login; 
     } 
    } 

adminUsername 및 ADMINPASSWORD에 도움이 관리 권한이있는 사용자의 자격 증명 (그래서 당신은 아마) 인스턴스에

O365 ADMIN 사이트의 UserProfileService.asmx 끝점에서 UserProfileService를 찾을 수 있습니다.

+0

그쪽으로 답변 카르마에 대한 nks. 나는 이것을 시도하고 알릴 것이다! –

+0

잘 작동합니다! 시간 내 주셔서 감사합니다 카르마 !!!!! –

관련 문제