关于Sharepoint 用户管理

using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.DirectoryServices;
using System.Collections;

namespace DMS.Layouts
{
  public partial class CUsers : LayoutsPageBase
  {
  protected void Page_Load(object sender, EventArgs e)
  {
  SPSite site = new SPSite("http://localhost");
  SPWeb web = site.OpenWeb();
   
  SPUserCollection users = web.SiteUsers;
  SPGroupCollection groups = web.SiteGroups;
  //users.Add(@"HNOP\zhoujieming","abc@hnop.com","","");
  web.AllowUnsafeUpdates = true;
  users.Remove(@"HNOP\zhoujieming");
 Response.Write("<b>SharePoint用户组:</b><br>");
  foreach(SPGroup group in groups)
  {
  Response.Write(group.Name + "<br>");
  }
   
   
  Response.Write("<b>SharePoint用户:</b><br>");
  foreach (SPUser user in users)
  {
  Response.Write(user.LoginName+"<br>");
  }
//获取站内有有角色
  Response.Write("<b>SharePoint角色:</b><br>");
  for (int i = 0; i < web.RoleDefinitions.Count; i++)
  {
   
  Response.Write(web.RoleDefinitions[i].Name+"<br>");
  }
  SPUser guser = web.EnsureUser(@"CLASS-15\student2");
   
  SPRoleAssignment roleAssignment = new SPRoleAssignment(web.EnsureUser(@"CLASS-15\student2"));
  roleAssignment.RoleDefinitionBindings.Add(web.RoleDefinitions["SLK Learner"]);
  web.RoleAssignments.Add(roleAssignment);
  /*
  //获取域,域计算机
  using (DirectoryEntry root = new DirectoryEntry("WinNT:"))
  {
  foreach (DirectoryEntry domain in root.Children)
  {
  Response.Write("Domain | WorkGroup:\t" + domain.Name+"<br>");
  foreach (DirectoryEntry computer in domain.Children)
  {
  Response.Write("Computer:\t" + computer.Name + "<br>");
  }
  }
  }
  Response.Write("<b>本机用户:</b><br>");
 DirectoryEntry LAd = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");


 foreach (object member in (IEnumerable)LAd.Invoke("Members"))
 {

  DirectoryEntry dirmem = new DirectoryEntry(member);
  Response.Write(dirmem.Name + "<br>");
 }



  Response.Write("<b>HOPN域用户:</b>");
  DirectoryEntry de = new DirectoryEntry();

  de.Path = "LDAP://CLASS-15/CN=Users,=DCgaochun,DC=jsmstc";
  de.Username = @"LASS-15\Administrator";
  de.Password = "password";

  //通过搜索查出所有的人员
  SearchResultCollection results;
  DirectorySearcher srch = new DirectorySearcher(de);
  srch.Filter = "(&(&(objectCategory=person)(objectClass=user)))";
  results = srch.FindAll();

  foreach (SearchResult sr in results)
  {
  DirectoryEntry objDE = sr.GetDirectoryEntry();
  string userName = objDE.Name.Substring(3);
  Response.Write(userName);
  } */
  //DirectoryEntry ADRoot = new DirectoryEntry("GC://dc=home,dc=duncanmackenzie,dc=net", "", "");
  }
   
  }
}


using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.DirectoryServices;
using System.Collections;

namespace DMS.Layouts
{
  public partial class CUsers : LayoutsPageBase
  {
  protected void Page_Load(object sender, EventArgs e)
  {
  SPSite site = new SPSite("http://localhost");
  SPWeb web = site.OpenWeb();
   
  SPUserCollection users = web.SiteUsers;
  SPGroupCollection groups = web.SiteGroups;
  //users.Add(@"HNOP\zhoujieming","abc@hnop.com","","");
  web.AllowUnsafeUpdates = true;
  users.Remove(@"HNOP\zhoujieming");
 Response.Write("<b>SharePoint用户组:</b><br>");
  foreach(SPGroup group in groups)
  {
  Response.Write(group.Name + "<br>");
  }
   
   
  Response.Write("<b>SharePoint用户:</b><br>");
  foreach (SPUser user in users)
  {
  Response.Write(user.LoginName+"<br>");
  }
//获取站内有有角色
  Response.Write("<b>SharePoint角色:</b><br>");
  for (int i = 0; i < web.RoleDefinitions.Count; i++)
  {
   
  Response.Write(web.RoleDefinitions[i].Name+"<br>");
  }
  SPUser guser = web.EnsureUser(@"CLASS-15\student2");
   
  SPRoleAssignment roleAssignment = new SPRoleAssignment(web.EnsureUser(@"CLASS-15\student2"));
  roleAssignment.RoleDefinitionBindings.Add(web.RoleDefinitions["SLK Learner"]);
  web.RoleAssignments.Add(roleAssignment);
  /*
  //获取域,域计算机
  using (DirectoryEntry root = new DirectoryEntry("WinNT:"))
  {
  foreach (DirectoryEntry domain in root.Children)
  {
  Response.Write("Domain | WorkGroup:\t" + domain.Name+"<br>");
  foreach (DirectoryEntry computer in domain.Children)
  {
  Response.Write("Computer:\t" + computer.Name + "<br>");
  }
  }
  }
  Response.Write("<b>本机用户:</b><br>");
 DirectoryEntry LAd = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");


 foreach (object member in (IEnumerable)LAd.Invoke("Members"))
 {

  DirectoryEntry dirmem = new DirectoryEntry(member);
  Response.Write(dirmem.Name + "<br>");
 }



  Response.Write("<b>HOPN域用户:</b>");
  DirectoryEntry de = new DirectoryEntry();

  de.Path = "LDAP://CLASS-15/CN=Users,=DCgaochun,DC=jsmstc";
  de.Username = @"LASS-15\Administrator";
  de.Password = "password";

  //通过搜索查出所有的人员
  SearchResultCollection results;
  DirectorySearcher srch = new DirectorySearcher(de);
  srch.Filter = "(&(&(objectCategory=person)(objectClass=user)))";
  results = srch.FindAll();

  foreach (SearchResult sr in results)
  {
  DirectoryEntry objDE = sr.GetDirectoryEntry();
  string userName = objDE.Name.Substring(3);
  Response.Write(userName);
  } */
  //DirectoryEntry ADRoot = new DirectoryEntry("GC://dc=home,dc=duncanmackenzie,dc=net", "", "");
  }
   
  }
}

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值