一流的网站建设流程图,电子商务网站建设干货,wordpress 过滤,网站头部模板C#中 DirectoryEntry组件应用实例DirectoryEntry类封装Active Directory层次结构中的节点或对象#xff0c;使用该类可以绑定到对象#xff0c;或者读取和更新属性。图1所示为DirectoryEntry组件。DirectoryEntry组件1#xff0e; 功能DirectoryEntry类封装Active Director… C#中 DirectoryEntry组件应用实例DirectoryEntry类封装Active Directory层次结构中的节点或对象使用该类可以绑定到对象或者读取和更新属性。图1所示为DirectoryEntry组件。 DirectoryEntry组件1 功能DirectoryEntry类封装Active Directory层次结构中的节点或对象使用该类可以绑定到对象或者读取和更新属性。图1所示为DirectoryEntry组件。图1 DirectoryEntry组件2属性DirectoryEntry组件常用属性及说明如表1所示。表1 DirectoryEntry组件常用属性及说明下面对比较重要的属性进行详细介绍。Path属性用于获取或设置DirectoryEntry对象的路径默认值为空字符串“”。语法 public string Path { get; set; }属性值DirectoryEntry对象的路径默认值为空字符串“”。示例Path属性的使用本示例主要是设置Path属性将本机上的用户名、工作组添加到treeview控件中。其运行结果如图2所示。图2 Path属性程序主要代码如下 完整程序代码如下★★★★★主程序文件完整程序代码★★★★★ using System; using System.Collections.Generic; using System.Windows.Forms; namespace _8_26 { static class Program { /// summary /// 应用程序的主入口点。/// /summary [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new frmDirectoryEntry()); } } }★★★★★frmDirectoryEntry窗体设计文件完整程序代码★★★★★ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.DirectoryServices; using System.Diagnostics; namespace _8_26 { public partial class frmDirectoryEntry : Form { public frmDirectoryEntry() { InitializeComponent(); } //以下函数实现路径及属性的添加功能private void AddPathAndProperties(TreeNode node, DirectoryEntry entry) { node.Nodes.Add(new TreeNode(Path: entry.Path)); TreeNode propertyNode new TreeNode(Properties); node.Nodes.Add(propertyNode); foreach (string propertyName in entry.Properties.PropertyNames) { string oneNode propertyName : entry.Properties[propertyName][0].ToString(); propertyNode.Nodes.Add(new TreeNode(oneNode)); } } private void frmDirectoryEntry_Load(object sender, EventArgs e) { //entryPC.Path WinNT://192.168.1.96/ZHY; entryPC.Path WinNT://workgroup/Localhost;//Workgroup计算机所处的组//ZHY计算机名//entryPC.Path LDAP://ZHY/rootDSE; TreeNode users new TreeNode(Users); TreeNode groups new TreeNode(Groups); TreeNode services new TreeNode(Services); viewPC.Nodes.AddRange(new TreeNode[] { users, groups, services }); foreach (DirectoryEntry child in entryPC.Children) { TreeNode newNode new TreeNode(child.Name); switch (child.SchemaClassName) { case User: users.Nodes.Add(newNode); break; case Group: groups.Nodes.Add(newNode); break; case Service: services.Nodes.Add(newNode); break; } AddPathAndProperties(newNode, child); //http://www.isstudy.com } } }// } namespace _8_26 { partial class frmDirectoryEntry { /// summary /// 必需的设计器变量。 /// /summary private System.ComponentModel.IContainer components null; /// summary /// 清理所有正在 namespace _8_26 { partial class frmDirectoryEntry { /// summary /// 必需的设计器变量。/// /summary private System.ComponentModel.IContainer components null; /// summary /// 清理所有正在使用的资源。/// /summary /// param namedisposing如果应释放托管资源为 true否则为 false。/param protected override void Dispose(bool disposing) { if (disposing (components ! null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows 窗体设计器生成的代码/// summary /// 设计器支持所需的方法 - 不要/// 使用代码编辑器修改此方法的内容。/// /summary private void InitializeComponent() { this.entryPC new System.DirectoryServices.DirectoryEntry(); this.viewPC new System.Windows.Forms.TreeView(); this.SuspendLayout(); // // viewPC // this.viewPC.Location new System.Drawing.Point(44, 26); this.viewPC.Name viewPC; this.viewPC.Size new System.Drawing.Size(195, 97); this.viewPC.TabIndex 0; // // frmDirectoryEntry // this.ClientSize new System.Drawing.Size(292, 184); this.Controls.Add(this.viewPC); this.Name frmDirectoryEntry; this.Load new System.EventHandler(this.frmDirectoryEntry_Load); this.ResumeLayout(false); } #endregion private System.DirectoryServices.DirectoryEntry entryPC; private System.Windows.Forms.TreeView viewPC; } }Path属性的语法将会随着提供程序的不同而不同。一些常见的情况如下所示。1WinNT。① 连接到计算机上的组。例如“WinNT://域名/计算机名/组名”。如果是连接到本地计算机则为“WinNT://计算机名/组名”。② 连接到计算机上的用户。例如“WinNT://域名/计算机名/用户名”。如果是连接到本地计算机则为“WinNT://计算机名/用户名”。③ 连接到计算机上的服务。例如“WinNT://域名/计算机名/服务名”。如果是连接到本地计算机则为“WinNT://计算机名/服务名”。④ 发现网络上的所有域。例如“WinNT:”。通过枚举此项的子级可以找到这些域。2LDAP。① 连接到域中的组。例如“LDAP://CN组名, CN 用户, DC域控制器 1, DC域控制器 2,...”。② 连接到域中的用户。例如“LDAP://CN完整用户名, CN用户, DC域控制器 1, DC域控制器 2,...”。③ 连接到域中的计算机。例如“LDAP://CN计算机名, CN计算机, DC域控制器 1, DC域控制器 2,...”。3IIS。① 连接到Web目录。例如“IIS://LocalHost/W3SVC/1/ROOT/Web 目录名”。② 若要使用LDAP绑定到当前域请使用路径“LDAP://RootDSE”然后获取默认命名上下文并重新绑定该项。3方法Exists方法用于确定指定路径是否表示目录的实际项。语法 public static bool Exists (string path) path要验证项的路径。 返回值如果指定路径表示目录服务的实际项则为True否则为False。path要验证项的路径。返回值如果指定路径表示目录服务的实际项则为True否则为False。