Hello,
I'm trying to use the System.DirectoryServices namespace with C# in order to
connect to our Novell eDirectory tree and get some information. The problem
I am encountering is that when I explicitly want to pull out the surname for
instance, I am still retrieving every entry for that user. If anyone can
take a look at the following code and point me in the correct direction:
using System;
using System.DirectoryServices;
namespace ConsoleApplication1
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
DirectoryEntry mainEntry = new DirectoryEntry( "LDAP://10.0.0.30" );
System.DirectoryServices.DirectorySearcher mySearcher = new
System.DirectoryServices.DirectorySearcher( mainEntry );
mySearcher.Filter = "(sn=bow*)";
mySearcher.PropertiesToLoad.Add( "cn" );
mySearcher.PropertyNamesOnly = true;
System.DirectoryServices.SearchResultCollection resCollection =
mySearcher.FindAll();
foreach(System.DirectoryServices.SearchResult resEnt in resCollection )
{
DirectoryEntry thisEntry = resEnt.GetDirectoryEntry();
foreach( string propName in thisEntry.Properties.PropertyNames )
{
try
{
foreach( object propValue in thisEntry.Properties[propName] )
{
Console.WriteLine( propName + ": " + propValue );
}
}
catch( System.Runtime.InteropServices.COMException e )
{
System.Console.WriteLine( "Exception Encountered...Continuing..." );
continue;
}
}
}
}
}
}
Any help would be greatly appreciated as I'm pretty stuck on this one and
feel I am doing it correctly. Thanks in advance!
-Mike
|