Directory Services |
The following code example shows how to use InvokeMember to retrieve the IADsUser properties FirstName and LastName from a managed code application.
[C#]
using System.Reflection;
using System.DirectoryServices;
...
DirectoryEntry ent = new DirectoryEntry("LDAP://CN=My User,DC=Fabrikam,DC=com");
Object ads = ent.NativeObject;
Type type = ads.GetType();
String firstName = (string) type.InvokeMember("FirstName", BindingFlags.GetProperty, null, ads, null);
String lastName = (string) type.InvokeMember("LastName", BindingFlags.GetProperty, null, ads, null);
The following code example shows how to set the Description property using InvokeMember.
using System.Reflection; using System.DirectoryServices; ... DirectoryEntry ent = new DirectoryEntry("LDAP://CN=My User,DC=Fabrikam,DC=com"); Object ads = ent.NativeObject; Type type = ads.GetType(); type.InvokeMember("Description", BindingFlags.SetProperty, null, ads, new object[] {"some description"}); de.CommitChanges();