Directory Programming .NET

Active Directory and ADAM programming support for .NET developers
Welcome to Directory Programming .NET Sign in | Join | Help
in Search

SearchResult Collection Property Name not retaining case

Last post 06-19-2007, 2:12 AM by sallas. 3 replies.
Sort Posts: Previous Next
  •  06-11-2007, 11:30 PM 1168

    SearchResult Collection Property Name not retaining case

     It seems (from errors I am getting) that the SearchResult class in retrieving Property Names from the AD stores them ignoring the case they were originally in (they are stored in lower case). Is there anyway to copy the Property Names retaining their case? 

    Code I am using is below (it is the variable 'myKey' that returns the Property Name that is always lower case, irrespective of what it is in the AD) 

    1    foreach(SearchResult result in mySearcher.FindAll()) 
    2 {
    3 ResultPropertyCollection myResultPropColl;
    4 myResultPropColl = result.Properties;
    5
    6 // Loop through Group Properties expoprting data
    7 foreach( string myKey in myResultPropColl.PropertyNames)
    8 {
    9
    10 foreach( Object myCollection in myResultPropColl[myKey])
    11 {
    12 tw.Write(myKey + ": " + myCollection);
    13 .
    14
    15 .
    16
    17

    So in finding the Property Name "dateOfBirth" in the AD, it is actually returned as "dateofbirth" causing the below case statement to be ignored:
    1 switch (fieldname)
    2 {
    3 case "dateOfBirth:": .
    The search code (as listed first) is acutally a seperate Project, with the 'Switch' statement being only one of many (for digfferent objects in the AD) in a different project that at this stage I cant really modify. So I was hoping there was some way I could ensure what is returned from the AD is in the correct case.
  •  06-12-2007, 12:00 PM 1170 in reply to 1168

    Re: SearchResult Collection Property Name not retaining case

    The collection model internally stores the property names in a case insentive collection model, so the property names are all lower case when using the PropertyNames property to enumerate them.  If you need to handle them in a case sensitive way, you can assume lower case.  In general, LDAP attribute names are not supposed to be treated as case sensitive.
  •  06-12-2007, 7:36 PM 1177 in reply to 1168

    Re: SearchResult Collection Property Name not retaining case

    You are going to have to force to lowercase (or upper) in your comparison to be truly robust since we have no real idea when or if that convention in .NET will change.

    Ryan Dunn
    Extemporaneous Mumblings
    The .NET Developer's Guide to Directory Services Programming
  •  06-19-2007, 2:12 AM 1215 in reply to 1177

    Re: SearchResult Collection Property Name not retaining case

    Thanks guys, have modified case statements to suit
View as RSS news feed in XML