这里有一系列带有代码的博客文章,展示了如何实现该操作:
(第一个博客展示了如何导入照片,第二个展示了如何导出照片)
AD中使用jpegPhoto属性-第一部分
AD中使用jpegPhoto属性-第二部分
编辑: 这里有一个通用函数,实现了第一部分的代码:
void AddPictureToUser(
string strDN, // User Distinguished Name, in the form "CN=Joe User,OU=Employees,DC=company,DC=local"
string strDCName, // Domain Controller, ie: "DC-01"
string strFileName // Picture file to open and import into AD
)
{
System.IO.FileStream inFile = new System.IO.FileStream(strFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
byte[] binaryData = new byte[inFile.Length];
int bytesRead = inFile.Read(binaryData, 0, (int)inFile.Length);
inFile.Close();
System.DirectoryServices.DirectoryEntry myUser = new System.DirectoryServices.DirectoryEntry(@"LDAP://" + strDCName + @"/" + strDN);
myUser.Properties["jpegPhoto"].Clear();
myUser.Properties["jpegPhoto"].Add(binaryData);
myUser.CommitChanges();
}
编辑:我发现在我的组织中,正确的属性设置应该是"thumbnailPhoto",像这样:
myUser.Properties["thumbnailPhoto"].Add(binaryData)
这似乎也是商业产品Exclaimer正在设置的内容(但它可能只在我的组织中这样做)。