2015-06-12 47 views
0

我是新的API的&試圖從共享點拉用戶配置文件我使用下面的代碼,但不知道服務器名?域名?和用戶名?我怎樣才能從共享點拉配置文件圖像

const string serverUrl = "http://sharepoint.com/"; 
      const string targetUser = "ttgdev-my.sharepoint.com\\[email protected]"; 

      // Connect to the client context. 
      ClientContext clientContext = new ClientContext(serverUrl); 

      // Get the PeopleManager object and then get the target user's properties. 
      PeopleManager peopleManager = new PeopleManager(clientContext); 
      PersonProperties personProperties = peopleManager.GetPropertiesFor(targetUser); 

      // Load the request and run it on the server. 
      // This example requests only the AccountName and UserProfileProperties 
      // properties of the personProperties object. 
      clientContext.Load(personProperties, p => p.AccountName, p => p.UserProfileProperties); 
      clientContext.ExecuteQuery(); 

      foreach (var property in personProperties.UserProfileProperties) 
      { 
       Console.WriteLine(string.Format("{0}: {1}", 
        property.Key.ToString(), property.Value.ToString())); 
      } 
      Console.ReadKey(false); 

請指引我,它會給我的錯誤中 {「的屬性或字段‘UserProfileProperties’尚未初始化,它並沒有被要求或請求尚未執行,這可能需要有明確要求。「} 以下行

clientContext.ExecuteQuery(); 
+0

是它的SharePoint在線或前提? –

+0

不,我想只通過使用此 – user3253756

+0

訪問userprofile圖片什麼不?我只是問你正在使用哪個SharePoint **版本** –

回答

0

最有可能與targetUser變量的格式有關。 PeopleManager.GetPropertiesFor method期望以適當的格式被指定accountName參數,在SharePoint在線的情況下,應該在權利要求中指定格式,例如:

i:0#.f|membership|[email protected] 

有關權利要求格式的更多細節如下this article

所以,你的情況targetUser值應該從​​更換,i:0#.f|membership|[email protected]


下面的例子演示瞭如何通過CSOM API獲取用戶的個人資料圖片:

​​