Example #1
0
        /// <summary>
        /// Get groups from a specified domain
        /// </summary>
        private void GetADGroups(string strDomain)
        {
            try
            {
                System.DirectoryServices.DirectoryEntry entry = new System.DirectoryServices.DirectoryEntry("LDAP://" + strDomain);
                entry.AuthenticationType = AuthenticationTypes.Secure;
                System.DirectoryServices.DirectorySearcher mySearcher =
                    new System.DirectoryServices.DirectorySearcher(entry);
                mySearcher.Filter = "(&(objectCategory=group))";

                System.DirectoryServices.SortOption sortOption = new
                                                                 System.DirectoryServices.SortOption("name",
                                                                                                     System.DirectoryServices.SortDirection.Ascending);
                mySearcher.Sort = sortOption;

                lstGroups.Items.Clear();
                AccessManager objAccess = new AccessManager();
                DataTable     objTable  = objAccess.GetGroups();
                objTable.DefaultView.Sort = "GroupDesc";

                foreach (System.DirectoryServices.SearchResult resEnt in mySearcher.FindAll())
                {
                    try
                    {
                        System.DirectoryServices.DirectoryEntry de = resEnt.GetDirectoryEntry();

                        // Get group name
                        string strGroupName = de.Properties["name"].Value.ToString();
                        // Verify if group allready exists on OfficeWorks
                        int RowNum = objTable.DefaultView.Find(strGroupName);

                        // If group does no exists
                        if (RowNum == -1)
                        {
                            lstGroups.Items.Add(strGroupName);
                        }
                    }
                    catch (Exception ex)
                    {
                        OfficeWorksException.WriteEventLog(ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                OfficeWorksException.WriteEventLog(ex.Message);
            }
        }