示例#1
0
        /// <summary>
        /// Returns the full ADSPath of the parent of this object
        /// </summary>
        /// <returns></returns>
        public ADSPath GetParent()
        {
            // Build a new parent, using the same prefix and suffix as This object.  Just replace the parentDN
            string  parentDN = GetParentDN();
            string  fullPath = BuildFullPath(Prefix, parentDN, Suffix);
            ADSPath obj      = new ADSPath(fullPath);

            return(obj);
        }
示例#2
0
        /// <summary>
        /// Builds a new ADSPath child container that has a parent of the current container.  The CN will be dropped of the current path name.
        /// <para>Example:  Current Path = LDAP://ou=office,dc=some,dc=local   New Child LDAP://ou=New Jersey,ou=office,dc=some,dc=local</para>
        /// </summary>
        /// <param name="childPart">The child container of the current object.  In format:  OU=child or OU=grandchild,OU=child</param>
        /// <returns></returns>
        public ADSPath NewChildADSPath(string childPart)
        {
            // Validate the childPart
            string childPartLC = childPart.ToLower();

            if (!(childPartLC.StartsWith("ou=") || childPartLC.StartsWith("o=")))
            {
                throw new ArgumentException("Invalid ChildPart.  Child part must start with OU= or O=.  You cannot access a child by specifiying cn= either.");
            }

            if (childPartLC.EndsWith(","))
            {
                childPart = childPart.TrimEnd(',');
            }


            // Need to strip leading CN= off.
            string childDN = "";
            string dnLC    = DN.ToLower();
            int    start   = -1;

            if (dnLC.StartsWith("cn="))
            {
                // TODO - Should also check for O=
                start = dnLC.IndexOf(",ou=");
                //if ( start == -1 ) start = dnLC.IndexOf(",dc=");
                if (start > 0)
                {
                    childDN = DN.Substring(start);
                }
                else
                {
                    childDN = DN;
                }
            }
            else
            {
                childDN = DN;
            }

            if (childDN.Length == 0)
            {
                childDN = childPart;
            }
            else if (childDN.StartsWith(","))
            {
                childDN = childPart + childDN;
            }
            else
            {
                childDN = childPart + "," + childDN;
            }


//			string childDN = childPart + "," + DN;

            string  childPath    = BuildFullPath(Prefix, childDN, Suffix);
            ADSPath childADSPath = new ADSPath(childPath);

            return(childADSPath);
        }