2012-12-30 62 views
3

試圖搜索Active Directory的非空描述對用戶(這意味着他們有一個職位),如下行4見過,但我得到一個錯誤,我無法使用排除!排除在PrincipalSearcher QueryFilter在C#空結果爲Active Directory

建議另一種方法?

PrincipalContext ctx = new PrincipalContext(ContextType.Domain); 
UserPrincipal qbeUser = new UserPrincipal(ctx); 
PrincipalSearcher srch = new PrincipalSearcher(qbeUser); 
var example = new UserPrincipal(ctx) { Description != null }; 
+2

什麼錯誤信息你好嗎? –

回答

2

我會嘗試這樣的事:

using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain)) 
{ 
    UserPrincipal qbeUser = new UserPrincipal(ctx); 
    qbeUser.Description = "*"; // something, anything - just not empty/NULL 

    PrincipalSearcher srch = new PrincipalSearcher(qbeUser); 
    ...... 
} 

這是否對你的工作?基本上,只要確定在qbeUser財產,使用*作爲通配符說,你要具有在Description財產用戶的東西 - 什麼東西,任何東西 - 只是並非一無是處。