在程序中使用System.DirectoryServices命名空间中的DirectoryEntry和DirectorySearcher类进行连接Active Directory,并使用PropertyCollection和DirectoryEntry对象来获取和设置thumbnailPhoto
和jpegPhoto
字段中的图像数据。具体示例代码如下:
DirectoryEntry entry = new DirectoryEntry("LDAP://your.domain.com");
DirectorySearcher searcher = new DirectorySearcher(entry);
searcher.Filter = "(&(objectClass=user)(sAMAccountName=johndoe))";
SearchResult result = searcher.FindOne();
if (result.Properties.Contains("thumbnailPhoto"))
{
byte[] thumbnail = (byte[])result.Properties["thumbnailPhoto"][0];
}
if (result.Properties.Contains("jpegPhoto"))
{
byte[] jpeg = (byte[])result.Properties["jpegPhoto"][0];
}