Novell.Directory.Ldap.LdapConnection.FetchSchema C# (CSharp) Method

FetchSchema() public method

Retrieves the schema associated with a particular schema DN in the directory server. The schema DN for a particular entry is obtained by calling the getSchemaDN method of LDAPConnection
LDAPException This exception occurs if the schema entry /// cannot be retrieved with this connection. ///
public FetchSchema ( System schemaDN ) : LdapSchema
schemaDN System The schema DN used to fetch the schema. /// ///
return LdapSchema
        public virtual LdapSchema FetchSchema(System.String schemaDN)
        {
            LdapEntry ent = Read(schemaDN, LdapSchema.schemaTypeNames);
            return new LdapSchema(ent);
        }

Usage Example

 static void Main(string[] args)
 {
     if ( args.Length != 6)
     {
         Console.WriteLine("Usage:   mono GetAttributeSchema <host name> <ldap port>  <login dn>" + " <password> <search base>" + " <search filter>");
         Console.WriteLine("Example: mono GetAttributeSchema Acme.com 389"  + " \"cn=admin,o=Acme\"" + " secret \"ou=sales,o=Acme\"" + "         \"(objectclass=*)\"");
         return;
     }
     string ldapHost = args[0];
     int ldapPort = System.Convert.ToInt32(args[1]);
     String loginDN  = args[2];
     String password = args[3];
     String searchBase = args[4];
     String searchFilter = args[5];
     try
     {
         LdapConnection conn= new LdapConnection();
         Console.WriteLine("Connecting to:" + ldapHost);
         conn.Connect(ldapHost,ldapPort);
         conn.Bind(loginDN,password);
         LdapSchema dirschema=conn.FetchSchema(conn.GetSchemaDN());
         LdapSearchResults lsc=conn.Search(  searchBase,
             LdapConnection.SCOPE_ONE,
             searchFilter,
             null,
             false);
         while (lsc.hasMore())
         {
             LdapEntry nextEntry = null;
             try
             {
                 nextEntry = lsc.next();
             }
             catch(LdapException e)
             {
                 Console.WriteLine("Error: " + e.LdapErrorMessage);
                 // Exception is thrown, go for next entry
                 continue;
             }
             Console.WriteLine("\n\n\n");
             Console.WriteLine("\n" + nextEntry.DN);
             LdapAttributeSet attributeSet = nextEntry.getAttributeSet();
             System.Collections.IEnumerator ienum=attributeSet.GetEnumerator();
             while(ienum.MoveNext())
             {
                 LdapAttribute attribute=(LdapAttribute)ienum.Current;
                 string attributeName = attribute.Name;
                 Console.WriteLine(  attributeName + ":  " + dirschema.getAttributeSchema(attributeName).ToString());
             }
         }
         conn.Disconnect();
     }
     catch(LdapException e)
     {
         Console.WriteLine("Error:" + e.LdapErrorMessage);
         return;
     }
     catch(Exception e)
     {
         Console.WriteLine("Error:" + e.Message);
         return;
     }
 }