Novell Home

Connect and Bind LDAP with Mono C-sharp

From Developer Community

This sample code shows how to connect to an openldap server using Novell.Directory.Ldap and Mono C#

Sample Code

using System;
using Novell.Directory.Ldap;

namespace ldapfinder
{
	class MainClass
	{
		public static void Main(string[] args)
		{
                        // Define server name and dc
			string server = "localhost";
			string dn = "dc=nodomain";
			
                        // Create a new LdapConnection instance
			LdapConnection conn = new LdapConnection();
                        // Connect to the server
			conn.Connect(server, 389);
                        // Get some data from server
			LdapEntry res = conn.Read(dn);
                        // Show the data gotten
			Console.WriteLine( "Resposta: {0}", res.ToString() );
			// Disconnect from server
			conn.Disconnect();
		}
	}
}

-- Aurelio Costa

© 2008 Novell, Inc. All Rights Reserved.