private void button1_Click_2(object sender, System.EventArgs e)
        {
            StringBuilder     builder    = new StringBuilder();
            AccessControlList acl        = new AccessControlList(util.SharedEntry);
            string            enumValues = null;

//			for(int	i=0;i<this.lstPermList.CheckedIndices.Count;i++)
//			{
//				PermissionItem o = (PermissionItem)lstPermList.Items[lstPermList.CheckedIndices[i]];
//				Console.Write("");
//			}

            IEnumerator myEnumerator;

            myEnumerator = this.lstPermList.CheckedIndices.GetEnumerator();
            int index;

            while (myEnumerator.MoveNext() != false)
            {
                index = (int)myEnumerator.Current;
                PermissionItem item = (PermissionItem)lstPermList.Items[index];
                builder.Append(item.EnumObject);
                builder.Append(',');
            }


            string          concatValue = builder.ToString().TrimEnd(new Char[] { ',' });
            ADS_RIGHTS_ENUM accessMask  = (ADS_RIGHTS_ENUM)Enum.Parse(typeof(ADS_RIGHTS_ENUM), concatValue);

            acl.ApplyPermission(this.cboTrustees.Text,
                                ADS_ACETYPE_ENUM.ADS_ACETYPE_ACCESS_ALLOWED,
                                accessMask,
                                ADS_ACEFLAG_ENUM.ADS_ACEFLAG_INHERIT_ACE,
                                ADS_FLAGTYPE_ENUM.ADS_FLAG_OBJECT_TYPE_PRESENT);



            acl.CommitChanges();

            LoadSecurity_Click(this, new EventArgs());
        }
        private void LoadAceDetails()
        {
            string schemaPath = "LDAP://";

            schemaPath += new DirectoryEntry("LDAP://RootDSE").Properties["schemaNamingContext"].Value.ToString();

            DirectoryEntry schemaEntry = new DirectoryEntry(schemaPath);

            schemaEntry.Path = "LDAP://CN=Users," + new DirectoryEntry("LDAP://RootDSE").Properties["defaultNamingContext"].Value.ToString();
            foreach (DirectoryEntry child in schemaEntry.Children)
            {
                try
                {
                    this.cboTrustees.Items.Add(child.Properties["userPrincipalName"].Value.ToString());
                }
                catch (Exception e)
                {
                }
            }


            foreach (string perm in Enum.GetNames(typeof(ADS_RIGHTS_ENUM)))
            {
                if (perm != Enum.GetName(typeof(ADS_RIGHTS_ENUM), ADS_RIGHTS_ENUM.ADS_RIGHT_DS_READ_PROP) ||
                    perm != Enum.GetName(typeof(ADS_RIGHTS_ENUM), ADS_RIGHTS_ENUM.ADS_RIGHT_DS_WRITE_PROP))
                {
                    object         p = Enum.Parse(typeof(ADS_RIGHTS_ENUM), perm);
                    PermissionItem o = new PermissionItem(Enum.Parse(typeof(ADS_RIGHTS_ENUM), perm),
                                                          AccessControlEntry.GetFriendlyName(perm));
                    this.lstPermList.Items.Add(
                        o, CheckState.Unchecked);
                    Console.Write("");
                }
            }

            hasLoadedSecInfo = true;
        }