views:

22

answers:

3

I am using the DirectoryServices.Protocols.SearchRequest type to make a request against an OpenDS store to retrieve 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.

A: 

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.

RonaldV
As far as I understood System.DirectoryServices was mainly used when dealing with Active directory. For other LDAP implementations recommended executions used the System.DirectoryServices.Protocols namespace. SearchRequest is the most commonly used type in there to perform retrievals against any ldap implementation.
Cranialsurge
A: 

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.

geoffc
A: 

Ironically this worked:-

SearchRequest searchRequest = new SearchRequest(hubTable, ldapFilter, SearchScope.Subtree, new[] { "AppId", "File" });
Cranialsurge