c#取出LDAP SearchResult所有属性

 string aaa = System.Threading.Thread.CurrentPrincipal.Identity.Name;

            DirectorySearcher ds = new DirectorySearcher();
            ds.SearchRoot = new DirectoryEntry("LDAP://888.888.0.11/CN=Users,DC=***,DC=com", "***", "***");
            ds.Filter = "(objectClass=user)";
            ds.SearchScope = SearchScope.Subtree;
            ds.Sort = new SortOption("Name", System.DirectoryServices.SortDirection.Ascending);
            ds.PageSize = 1024;
            SearchResultCollection rs = ds.FindAll();

            foreach (SearchResult r in rs)
            {
                ResultPropertyCollection rprops = r.Properties;
                string prop = null;
                foreach (string name in rprops.PropertyNames)
                {
                    foreach (object vl in rprops[name])
                    {
                        prop = name + ":" + vl.ToString();
                        ls.Add(prop);
                    }
                }
            }

posted @ 2016-04-28 22:40  金虹巴巴  阅读(2082)  评论(0编辑  收藏  举报