Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何找到部门经理_C#_Active Directory_Ldap - Fatal编程技术网

C# 如何找到部门经理

C# 如何找到部门经理,c#,active-directory,ldap,C#,Active Directory,Ldap,我目前正在使用Active Directory。我能列出在一个部门工作的每个人的名单,但我不知道如何分辨谁是经理 public void MemberOf(string department) { DirectoryEntry de = new DirectoryEntry("LDAP://server.server.com"); DirectorySearcher ds = new DirectorySearcher(de);

我目前正在使用Active Directory。我能列出在一个部门工作的每个人的名单,但我不知道如何分辨谁是经理

public void MemberOf(string department)
        {
            DirectoryEntry de = new DirectoryEntry("LDAP://server.server.com");

            DirectorySearcher ds = new DirectorySearcher(de);

            ds.Filter = ("(&(objectCategory=person)(objectClass=User)(department=" + department + "))");
            ds.SearchScope = SearchScope.Subtree;

            foreach (SearchResult temp in ds.FindAll())
            {
                string test1 = temp.Path;
            }
        }

这将返回一份人员列表,其中一人是经理,其他人是经理的直接下属。

这不是最好的实施方式,但不知道您想用它做什么……如何获取数据……等等,这是一个快速而肮脏的实施方式:

public void MemberOf(string department)
        {
            DirectoryEntry de = new DirectoryEntry("LDAP://server.server.com");

            DirectorySearcher ds = new DirectorySearcher(de);

            ds.Filter = ("(&(objectCategory=person)(objectClass=User)(department=" + department + "))");
            ds.SearchScope = SearchScope.Subtree;

            foreach (SearchResult temp in ds.FindAll())
            {
                string test1 = temp.Path;
            }
        }
private void Test(string department)
    {
        //Create a dictionary using the manager as the key, employees for the values
        List<Employee> employees = new List<Employee>();

        DirectoryEntry de = new DirectoryEntry("LDAP://server.server.com");
        DirectorySearcher ds = new DirectorySearcher(de);

        ds.Filter = String.Format(("(&(objectCategory=person)(objectClass=User)(department={0}))"), department);
        ds.SearchScope = SearchScope.Subtree;

        foreach (SearchResult temp in ds.FindAll())
        {
            Employee e = new Employee();

            e.Manager = temp.Properties["Manager"][0].ToString();
            e.UserId = temp.Properties["sAMAccountName"][0].ToString();
            e.Name = temp.Properties["displayName"][0].ToString();

            employees.Add(e);
        }
    }

    public class Employee
    {
        public string Name { get; set; }
        public string Manager { get; set; }
        public string UserId { get; set; }
    }
private void Test(字符串部门)
{
//创建一个字典,使用经理作为键,员工作为值
列出员工=新列表();
DirectoryEntry de=new DirectoryEntry(“LDAP://server.server.com”);
DirectorySearcher ds=新的DirectorySearcher(de);
ds.Filter=String.Format(“(&(objectCategory=person)(objectClass=User)(department={0}))”,department);
ds.SearchScope=SearchScope.Subtree;
foreach(ds.FindAll()中的SearchResult临时值)
{
员工e=新员工();
e、 Manager=temp.Properties[“Manager”][0].ToString();
e、 UserId=temp.Properties[“sAMAccountName”][0].ToString();
e、 Name=temp.Properties[“displayName”][0].ToString();
增加(e);
}
}
公营雇员
{
公共字符串名称{get;set;}
公共字符串管理器{get;set;}
公共字符串用户标识{get;set;}
}

你怎么知道?经理的
manager
属性是否为空?或者管理者是否有其他的、与众不同的财产价值?例如,经理是否属于其员工不属于的特定群体?我不确定这是问题的一部分。ManagerA有自己的经理。然后,员工将ManagerA列为他们的经理。我认为,必须有一种简单的方法来确定谁管理一个部门@marc_sWell,问题是:部门本身(即
OU
容器)没有manager属性。最有可能的是,会有一个类似“经理”的小组或一些你可以检查的东西——这是可靠地找到这些经理的最简单的方法。谢谢,这实际上帮助我到达了我需要的地方。:)仍然需要弄清楚如何辨别谁管理一个部门,但这确实帮助我克服了我一直坚持的其他问题。