The process of converting attributes that contain binary data is very similar to that used for the other standard data types. In this case, both Directory-Entry and DirectorySearcher will convert the attribute data to a single-dimensional array of bytes:
//given our DirectoryEntry entry //and SearchResult result from our previous examples byte[] sid = (byte[]) entry.Properties["objectSid"].Value; sid = (byte[]) result.Properties["objectSid"][0];
If the attribute contains multiple values, we simply do the same thing in a foreach loop:
foreach (byte[] cert in entry.Properties["userCertificate"]) { //do something useful... }
We can also use the Value property again here with PropertyValueCollection. In the case of multiple values, it will return a jagged array of byte arrays.
Part I: Fundamentals
Introduction to LDAP and Active Directory
Introduction to .NET Directory Services Programming
Binding and CRUD Operations with DirectoryEntry
Searching with the DirectorySearcher
Advanced LDAP Searches
Reading and Writing LDAP Attributes
Active Directory and ADAM Schema
Security in Directory Services Programming
Introduction to the ActiveDirectory Namespace
Part II: Practical Applications
User Management
Group Management
Authentication
Part III: Appendixes
Appendix A. Three Approaches to COM Interop with ADSI
Appendix B. LDAP Tools for Programmers
Appendix C. Troubleshooting and Help
Index