Cannot specify which attributes to return when querying an LDAP store
I am using the DirectoryServices.Protocols.SearchRequest type to make a request against an OpenDS store to retriev开发者_StackOverflowe some entries. I want to be able to control which attributes are returned for the entries in the response and thought the "Attributes" property would do it. However that property does not have a setter so I cannot do something like this:-
SearchRequest searchRequest = new SearchRequest
{
DistinguishedName = hubTable,
Filter = ldapFilter,
Scope = SearchScope.Subtree,
Attributes = new StringCollection{"Id", "File"}
};
//run the query and get the results
SearchResponse results = connection.SendRequest(searchRequest) as SearchResponse;
Can anyone direct me to what I should be doing to filter the request to only return entries with the specified attributes and not all of them.
Ironically this worked:-
SearchRequest searchRequest = new SearchRequest(hubTable, ldapFilter, SearchScope.Subtree, new[] { "AppId", "File" });
Is there a reason why you're using SearchResuest? In any case you can use the DirectorySearcher class http://msdn.microsoft.com/en-us/library/system.directoryservices.directorysearcher.aspx to lookup entries. Here is an example of looking up 1 result http://msdn.microsoft.com/en-us/library/system.directoryservices.searchresult.aspx. Use the FindAll method to get all the results.
I would suspect you would need a different filter.
I am sure your ldapfilter
has some criteria. You would need to AND it (with &) to include (&(Id=*)(File=*))
in order to get the results you are looking for.
精彩评论