Search code examples
.netldapdirectoryservicesopends

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 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.


Solution

  • Ironically this worked:-

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