I have a problem reading from our ldap server with DirectorySearcher.
For example when I'm retrieving data of people with a names like "René" or
"Jerôme" they appear in the SearchResult as "Ren" and "Jerme".
With a third party tool I can see that René is stored as "52 65 6E E9".
Because E9 >128 I'm affraid something is wrong with the DirectorySearcher
implementation, as I cannot retrieve those characters, even with the
Encoding GetString methods.
Anyone who knows a workaround?
Thanks,
Peter Aragon
"Peter Aragon" <pf...@nospam.oce.nl> wrote in message
news:eC48IxvI...@tk2msftngp13.phx.gbl...
Before we go further, could you answer the following questions please:
1>How did you use the DirectorySearcher in your code? And what attribute are you trying to retrieve? Could
you post a code snippet on it?
2>what's that 3rd tool? And how can I get the problem value from it?
Thanks. I am looking forward to hearing from you.
Have a great weekend!
Rhett Gong [MSFT]
Microsoft Online Partner Support
This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.
DirectoryEntry objDE = new DirectoryEntry(strPath, "", "", AuthenticationTypes.Anonymous);
PropertyValueCollection values = objDE.Properties["cn"];
object x = values.Value;
PrintObject(x, "hash");
static void PrintObject(object x, string name)
{
object[] a = x as object[];
System.Diagnostics.Debug.WriteLine(x.GetType());
System.Diagnostics.Debug.WriteLine(a[0].GetType());
System.Diagnostics.Debug.WriteLine(a.Length);
for (int i = 0; i < a.Length; ++i)
{
System.Diagnostics.Debug.WriteLine(name + "[" + i + "] = " + a[i]);
}
}
Thanks for the quick reply,
Peter Aragon
But I am still not clear on your problem, please help to answer following questions. Thanks.
1>How did you use DirectorySearcher for Rene? <--If i get this, I will know how to use "LDAP Browser" to check the value
2>What does "hash" mean in this line "PrintObject(x, "hash")"? Is this something special?
3>Could you post the problem code to let me see what happens on DirectorySearcher?
Have a nice day!
The only problem at the moment is that I can only get a string back from the
PropertyValueCollection. The entry in our LDAP for people with 'strange'
accents in their names are is stored as binary information. However the
DirectoryServices don't allow me to get to this raw binary information, the
return value is always an 'interpreted' string. This string however does not
contain the 'strange' characters.
So I want to know if there is a way to obtain the 'true' binary value from
the LDAP in stead of the return 'interpreted' string from DirectoryServices.
If there is a way to tell DirectoryServies which codepage to use to convert
the binary information into a string, that would also be ok.
Somehow the team who built DirectoryServices forgot that there are
situations where LDAP entry values are not necessarily UTF-8, but can also
be western european ISO chars.
I don't have any more code to give you, as this is the only code needed to
show the problem. Add a binary value "52 65 6E E9" to an LDAP and try to get
it back with DirectoryServices as "René".
Thanks,
Peter
"Rhett Gong [MSFT]" <v-ra...@online.microsoft.com> wrote in message
news:JFrZvfg...@cpmsftngxa10.phx.gbl...
byte[] binaryString = new byte[]{0x52,0x65,0x6e,0xe9, 0x20, 0x42, 0x72, 0xfc, 0x6e, 0x6b, 0x65, 0x6e};
//The effect occuring with DirectoryServices not showing René but Ren
//Only difference is that Brünken in DirectoryServices is shown as Br and nothing else.
MessageBox.Show( System.Text.Encoding.UTF8.GetString(binaryString) );
//The desired effect
MessageBox.Show( System.Text.Encoding.UTF7.GetString(binaryString) );
2> using .net DirectoryServices: apply this code to see if it could resolve your problem,
//-----------------------------------------------------------------
// negotiate with ldap server what locale it used. Assume it is Franch, then try following code.
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("fr",true);
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("fr",true);
//-----------------------------------------------------------------------
Please apply my suggestions and let me know your result. Thanks.
To no avail.
Setting the CultureInfo to fr got me the error: Culture "fr" is a neutral
culture. It can not be used in formatting and parsing and therefore cannot
be set as the thread's current culture. So I set it to "fr-FR" just to prove
setting the culture is not the right solution, and I get the same results .
It's not how the strings are put on screen, even in Debug mode when
switching to binary mode I don't see 4 but 3 characters for René (Ren). ,
and unless I get a byte array back or am able to set the encoding for the
string conversion of DirectoryServices Using ADsGetObject will certainly
work, it's just that the .NET way shows regression or less functionality and
it is a reason not to switch to .NET. I'm looking at a showstopper for this
project. The strings in the LDAP are encoded in UTF7. Changing the LDAP to
UTF8 is also no option, as a lot of legacy application still rely on UTF7
and don't understand UTF8.
So could you please forward this to the people within the .NET group
responsible for DirectoryServices as a feature request/bug report? Too bad
me or others haven't spotted this behavior during the last 2 beta trails of
.NET 1.0 and 1.1. So what I would want is the raw Byte array in stead of a
wrongly decoded string value, or give a hint to DirectoryServices on the
decoding scheme. Else how could you retrieve binary information from LDAP
with .NET if you would only get back a string?
Thanks,
Peter Aragon
"Rhett Gong [MSFT]" <v-ra...@online.microsoft.com> wrote in message
news:8alJC1BK...@cpmsftngxa10.phx.gbl...
> Hi,
> 1> use following lines (unmanaged code) to see if you can get the full
charaters especially 0xE9 returned at your client with different locale
setting.
>
//--------------------------------------------------------------------------
-------
> hr =
ADsGetObject(L"LDAP://test.microsoft.com/CN=Ren¨¦,CN=Users,DC=Test,DC=micros
>So could you please forward this to the people within the .NET group
>responsible for DirectoryServices as a feature request/bug report?
I have sent an email to them. If I get any answer for this problem, I will post it here.
Thanks and have a good day!