這裏更有用返回到圖像與代碼的一系列博客文章中,顯示瞭如何做到這一點:
(第一次顯示瞭如何獲取的照片,第二個顯示瞭如何把它弄出來)
Using the jpegPhoto attribute in AD - Part I
Using the jpegPhoto attribute in AD - Part II
編輯:下面是從第I部分執行代碼的通用功能:
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
)
{
// Open file
System.IO.FileStream inFile = new System.IO.FileStream(strFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
// Retrive Data into a byte array variable
byte[] binaryData = new byte[inFile.Length];
int bytesRead = inFile.Read(binaryData, 0, (int)inFile.Length);
inFile.Close();
// Connect to AD
System.DirectoryServices.DirectoryEntry myUser = new System.DirectoryServices.DirectoryEntry(@"LDAP://" + strDCName + @"/" + strDN);
// Clear existing picture if exists
myUser.Properties["jpegPhoto"].Clear();
// Update attribute with binary data from file
myUser.Properties["jpegPhoto"].Add(binaryData);
myUser.CommitChanges();
}
編輯:我發現,在我的組織,正確的屬性設置爲「thumbnailPhoto」是這樣的:
myUser.Properties["thumbnailPhoto"].Add(binaryData);
這也似乎TBE的一個商業產品Exclaimer被設置(但也可能是唯一的做,在我的組織)
之前,我試圖回答這個問題,你只是想插入圖片作爲對象插入的地方與用戶的Active Directory架構?或者您是否希望將照片實際分配爲用戶的個人資料圖片? – 2010-01-08 20:26:05