The following table contains a list of controls supported in the LDAP libraries for C#.
Table 5-1 Supported Controls
Server Side Sort: Returns results from a search operation in sorted order. This can be used to off-load processing from the client, or if you cannot sort the results for some reason.
Vertical List View: Works in conjunction with the server side sort control to provide a dynamic view of a scrolling list. This works in conjunction with the server side sort control.
Persistent Search and Entry Change Notification: Provides a control to perform a continuous search, notifying the application of changes.
Manage Dsa IT: Causes directory-specific entries, regardless of type, to be treated as normal entries.
The C# code fragments below shows how to use the server side control using the Novell.Directory.Ldap namespace. The code below is hard coded to sort based on the “sn” attribute, and it searches for all objects at the specified searchBase.
// C# Library namespace using Novell.Directory.Ldap; // Creating an LdapConnection instance LdapConnection ldapConn= new LdapConnection(); //Connect function will create a socket connection to the server ldapConn.Connect(ldapHost,ldapPort); //Bind function will Bind the user object Credentials to the Server ldapConn.Bind(userDN,userPasswd); String[] attrs = new String[1]; attrs[0] = "sn"; LdapSortKey[] keys = new LdapSortKey[1]; keys[0] = new LdapSortKey( "sn" ); // Create a LDAPSortControl object - Fail if cannot sort LdapSortControl sort = new LdapSortControl( keys, true ); // Set the Sort control to be sent as part of search request LdapSearchConstraints cons = ldapConn.SearchConstraints; cons.setControls( sort ); ldapConn.Constraints = cons; LdapSearchResults lsc=ldapConn.Search(searchBase, LdapConnection.SCOPE_SUB,searchFilter,attrs,false, LdapSearchConstraints)null ); 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" + nextEntry.DN); LdapAttributeSet attributeSet =nextEntry.getAttributeSet(); System.Collections.IEnumerator ienum = attributeSet.GetEnumerator(); while(ienum.MoveNext()) { LdapAttribute attribute=(LdapAttribute)ienum.Current; string attributeName = attribute.Name; string attributeVal = attribute.StringValue; Console.WriteLine( attributeName + "value:" + attributeVal); } } ldapConn.Disconnect();