Beispiel #1
0
        public List <ADUserInfo> getADUserInfo2(string find)
        {
            DirectoryEntry    de = new DirectoryEntry(path, Userid, Password);
            DirectorySearcher ds = new DirectorySearcher(de);

            ds.Filter = "(&(objectClass=user)(|(SAMAccountName=" + find.Trim() + ")))";
            List <ADUserInfo> ls_ADUserInfo = new List <ADUserInfo>();

            try
            {
                foreach (System.DirectoryServices.SearchResult resEnt in ds.FindAll())
                {
                    DirectoryEntry user = resEnt.GetDirectoryEntry();
                    if (user.Properties["Cn"].Value.ToString() != "")
                    {
                        ADUserInfo aduser = new ADUserInfo();
                        aduser.Co         = user.Properties["Co"].Value != null ? user.Properties["Co"].Value.ToString() : "";
                        aduser.St         = user.Properties["St"].Value != null ? user.Properties["St"].Value.ToString() : "";
                        aduser.L          = user.Properties["L"].Value != null ? user.Properties["L"].Value.ToString() : "";
                        aduser.Company    = user.Properties["Company"].Value != null ? user.Properties["Company"].Value.ToString() : "";
                        aduser.DepartMent = user.Properties["DepartMent"].Value != null ? user.Properties["DepartMent"].Value.ToString() : "";
                        aduser.Physicaldeliveryofficename = user.Properties["Physicaldeliveryofficename"].Value != null ? user.Properties["Physicaldeliveryofficename"].Value.ToString() : "";
                        aduser.Streetaddress = user.Properties["Streetaddress"].Value != null ? user.Properties["Streetaddress"].Value.ToString() : "";
                        aduser.Postalcode    = user.Properties["Postalcode"].Value != null ? user.Properties["Postalcode"].Value.ToString() : "";

                        aduser.Cn                       = user.Properties["Cn"].Value != null ? user.Properties["Cn"].Value.ToString() : "";
                        aduser.Displayname              = user.Properties["Displayname"].Value != null ? user.Properties["Displayname"].Value.ToString() : "";
                        aduser.SAMAccountName           = user.Properties["SAMAccountName"].Value != null ? user.Properties["SAMAccountName"].Value.ToString() : "";
                        aduser.Sn                       = user.Properties["Sn"].Value != null ? user.Properties["Sn"].Value.ToString() : "";
                        aduser.Givenname                = user.Properties["Givenname"].Value != null ? user.Properties["Givenname"].Value.ToString() : "";
                        aduser.Title                    = user.Properties["Title"].Value != null ? user.Properties["Title"].Value.ToString() : "";
                        aduser.Mail                     = user.Properties["Mail"].Value != null ? user.Properties["Mail"].Value.ToString() : "";
                        aduser.TelephoneNumber          = user.Properties["TelephoneNumber"].Value != null ? user.Properties["TelephoneNumber"].Value.ToString() : "";
                        aduser.Mobile                   = user.Properties["Mobile"].Value != null ? user.Properties["Mobile"].Value.ToString() : "";
                        aduser.Facsimiletelephonenumber = user.Properties["Facsimiletelephonenumber"].Value != null ? user.Properties["Facsimiletelephonenumber"].Value.ToString() : "";

                        aduser.Distinguishedname = user.Properties["Distinguishedname"].Value != null ? user.Properties["Distinguishedname"].Value.ToString() : "";

                        ls_ADUserInfo.Add(aduser);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                ds.Dispose();
                de.Dispose();
            }
            return(ls_ADUserInfo);
        }
Beispiel #2
0
        /// <summary>
        /// 获取组织架构列表
        /// </summary>
        /// <param name="find"> 值 </param>
        /// <param name="mode"> 参数 </param>
        /// <returns>组织架构列表集合</returns>
        public List <ADUnitInfo> getADUnitInfo_Next(string find)
        {
            DirectoryEntry    de = new DirectoryEntry(path, Userid, Password);
            DirectorySearcher ds = new DirectorySearcher(de);

            ds.Filter = "(objectClass=organizationalUnit)";

            List <ADUnitInfo> ls_ADUnitInfo = new List <ADUnitInfo>();
            List <ADUserInfo> ls_ADUserInfo = new List <ADUserInfo>();

            try
            {
                foreach (System.DirectoryServices.SearchResult resEnt in ds.FindAll())
                {
                    DirectoryEntry user = resEnt.GetDirectoryEntry();
                    if (user.Properties["Distinguishedname"].Value.ToString().IndexOf(find) >= 0)
                    {
                        ADUnitInfo aduser = new ADUnitInfo();
                        aduser.Name = user.Properties["Name"].Value != null ? user.Properties["Name"].Value.ToString() : "";
                        aduser.Distinguishedname = user.Properties["Distinguishedname"].Value != null ? user.Properties["Distinguishedname"].Value.ToString() : "";
                        aduser.Objectcategory    = user.Properties["Objectcategory"].Value != null ? user.Properties["Objectcategory"].Value.ToString() : "";
                        aduser.Whencreated       = DateTime.Parse(user.Properties["Whencreated"].Value.ToString());
                        aduser.Whenchanged       = DateTime.Parse(user.Properties["Whenchanged"].Value.ToString());

                        aduser.ADUserInfo = new List <ADUserInfo>();
                        ADUserInfo aduser3 = new ADUserInfo();
                        ls_ADUserInfo = getADUserInfo_Unit(aduser.Distinguishedname.ToString());
                        for (int i = 0; i < ls_ADUserInfo.Count; i++)
                        {
                            aduser3 = ls_ADUserInfo[i];
                            aduser.ADUserInfo.Add(aduser3);
                        }

                        aduser.NextUnit = new List <ADUnitInfo>();

                        ls_ADUnitInfo.Add(aduser);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                ds.Dispose();
                de.Dispose();
            }
            return(ls_ADUnitInfo);
        }