0

我的web应用程序是使用HTML5和Jquery的ASP.NET MVC 4 Web应用程序。检索和编辑Sharepoint Active Directory用户配置文件属性

我正在编写Web应用程序以使用Active Directory从Sharepoint服务器检索和编辑数据。

我可以检索信息,但我试图找出一种方法来编辑和提交更改到活动目录帐户。我一直无法找到与远程Web应用程序访问有关的代码示例。我所见过的唯一编辑样本只能在SharePoint服务器上完成。

我想知道我们是否完全忽略了有关Active Directory的事情,如果我试图做甚至可能。

注:

我一直没能找到的代码编辑Active Directory的信息呢。这是我目前检索的代码。我希望能够撤消信息,编辑名字或姓氏等属性,然后将更改提交到SharePoint Active Directory。

在此先感谢您的答案!

ClientContext currentContext = new ClientContext(serverAddress); 
     currentContext.Credentials = new System.Net.NetworkCredential(adminAccount, password); 

     const string targetUser = "domain\\targetAccountName"; 

     Microsoft.SharePoint.Client.UserProfiles.PeopleManager peopleManager = new Microsoft.SharePoint.Client.UserProfiles.PeopleManager(currentContext); 
     Microsoft.SharePoint.Client.UserProfiles.PersonProperties personProperties = peopleManager.GetPropertiesFor(targetUser); 

     currentContext.Load(personProperties, p => p.AccountName, p => p.UserProfileProperties); 
     currentContext.ExecuteQuery(); 

     foreach (var property in personProperties.UserProfileProperties) 
     { 
      //Pull User Account Name 
      //Edit Account name to new value 
      //Commit changes 
     }    

回答

0

看起来像PersonProperties类只提供只读访问,因为所有属性只显示Get。 MSDN PersonProperties

如果你想留在SharePoint,看起来你需要检查UserProfile class。该页面有一个体面的例子,可以检索一个帐户,然后设置一些属性。

如果您不需要SharePoint特定的属性并希望使用易于使用的格式,则可以检索UserPrincipal。它会让您轻松访问常见的用户属性。

using (var context = new PrincipalContext(ContextType.Domain, "domainServer", 
          "DC=domain,DC=local", adminAccount, password)) 
{ 
    var userPrincipal = UserPrincipal.FindByIdentity(context, 
          IdentityType.SamAccountName, "targetAccountName"); 
    if (userPrincipal != null) 
    { 
     userPrincipal.GivenName = "NewFirstName"; 
     // etc, etc. 
    } 
} 
+0

谢谢!这正是我所期待的。看起来好像有很多不同的方式来获取这些SharePoint特定的属性。 –

相关问题