我的任務是創建一個與活動目錄進行通信並獲取所有當前用戶的終極應用程序。我們正在維護一箇舊的Excel表格,所有新用戶都遇到問題,即當任何人離開組織時,他們不會被刪除,因此新用戶會被添加,但舊用戶也會留在Excel表格中,從而導致Excel表格增長,所以現在管理層想要 有一個桌面應用程序,他們可以用它來搜索用戶並獲取他/她的信息,但是我的應用程序比較滯後,例如選擇了用戶john,顯示john的電話號碼123-456-7890 now i選擇Joe下拉菜單中的最後一個用戶,所有信息都會更改,但手機文本框仍然保持值123-456-7890。我怎麼做錯了這裏和任何建議或解決方法將不勝感激。C#活動目錄應用程序在填充文本框時滯後
private void ShowUserInformation(SearchResult rs)
{
if (rs.GetDirectoryEntry().Properties["samaccountname"].Value != null)
username.Text = rs.GetDirectoryEntry().Properties["samaccountname"].Value.ToString();
if (rs.GetDirectoryEntry().Properties["givenName"].Value != null)
FirstName.Text = rs.GetDirectoryEntry().Properties["givenName"].Value.ToString();
if (rs.GetDirectoryEntry().Properties["initials"].Value != null)
MiddleName.Text = rs.GetDirectoryEntry().Properties["initials"].Value.ToString();
if (rs.GetDirectoryEntry().Properties["sn"].Value != null)
LastName.Text = rs.GetDirectoryEntry().Properties["sn"].Value.ToString();
if (rs.GetDirectoryEntry().Properties["mail"].Value != null)
email.Text = rs.GetDirectoryEntry().Properties["mail"].Value.ToString();
if (rs.GetDirectoryEntry().Properties["personalTitle"].Value != null)
title.Text = rs.GetDirectoryEntry().Properties["personalTitle"].Value.ToString();
if (rs.GetDirectoryEntry().Properties["company"].Value != null)
company.Text = rs.GetDirectoryEntry().Properties["company"].Value.ToString();
if (rs.GetDirectoryEntry().Properties["l"].Value != null)
city.Text = rs.GetDirectoryEntry().Properties["l"].Value.ToString();
if (rs.GetDirectoryEntry().Properties["st"].Value != null)
state.Text = rs.GetDirectoryEntry().Properties["st"].Value.ToString();
if (rs.GetDirectoryEntry().Properties["co"].Value != null)
country.Text = rs.GetDirectoryEntry().Properties["co"].Value.ToString();
if (rs.GetDirectoryEntry().Properties["memeberOf = IS Team"].Value != null)
Groups.Text = rs.GetDirectoryEntry().Properties["memeberOf = IS Team"].Value.ToString();
if (rs.GetDirectoryEntry().Properties["postalCode"].Value != null)
postalcode.Text = rs.GetDirectoryEntry().Properties["postalCode"].Value.ToString();
if (rs.GetDirectoryEntry().Properties["telephoneNumber"].Value != null)
phone.Text = rs.GetDirectoryEntry().Properties["telephoneNumber"].Value.ToString();
if (rs.GetDirectoryEntry().Properties["streetAddress"].Value != null)
address.Text = rs.GetDirectoryEntry().Properties["streetAddress"].Value.ToString();
if (rs.GetDirectoryEntry().Properties["department"].Value != null)
department.Text = rs.GetDirectoryEntry().Properties["department"].Value.ToString();
if (rs.GetDirectoryEntry().Properties["description"].Value != null)
descriptions.Text = rs.GetDirectoryEntry().Properties["description"].Value.ToString();
if (rs.GetDirectoryEntry().Properties["employeeID"].Value != null)
employee.Text = rs.GetDirectoryEntry().Properties["employeeID"].Value.ToString();
if (rs.GetDirectoryEntry().Properties["mobile"].Value != null)
mobile.Text = rs.GetDirectoryEntry().Properties["mobile"].Value.ToString();
if (rs.GetDirectoryEntry().Properties["accountExpires"].Value != null)
accountexpires.Text = rs.GetDirectoryEntry().Properties["accountExpires"].Value.ToString();
if (rs.GetDirectoryEntry().Properties["homeDrive"].Value != null)
homedrive.Text = rs.GetDirectoryEntry().Properties["homeDrive"].Value.ToString();
if (rs.GetDirectoryEntry().Properties["homeDirectory"].Value != null)
homedirectory.Text = rs.GetDirectoryEntry().Properties["homeDirectory"].Value.ToString();
if (rs.GetDirectoryEntry().Properties["whenCreated"].Value != null)
WhenCreate.Text = rs.GetDirectoryEntry().Properties["whenCreated"].Value.ToString();
if (rs.GetDirectoryEntry().Properties["lastLogoff"].Value != null)
lastloggedoff.Text = rs.GetDirectoryEntry().Properties["lastLogoff"].Value.ToString();
if (rs.GetDirectoryEntry().Properties["badPasswordTime"].Value != null)
badpassword.Text = rs.GetDirectoryEntry().Properties["badPasswordTime"].Value.ToString();
if (rs.GetDirectoryEntry().Properties["whenCreated"].Value != null)
WhenCreate.Text = rs.GetDirectoryEntry().Properties["whenCreated"].Value.ToString();
if (rs.GetDirectoryEntry().Properties["whenChanged"].Value != null)
whenchanged.Text = rs.GetDirectoryEntry().Properties["whenChanged"].Value.ToString();
是增加了一個斷點,郵件屬性設置併爲每個用戶的郵件屬性是變化的,所以像你說,如果一個用戶沒有一個電話號碼,但沒有更新,因此我們正在尋找來自以前的用戶的價值,但我甚至做了檢查,如果我選擇一個用戶沒有電話號碼的文本框值是空的,然後選擇一個用戶,如果電話號碼的價值改變,它只滯後於選擇範圍大得多例如選擇第一個用戶,立即選擇最後一個用戶將其關閉。 – 2014-10-29 14:24:19