Á
Ágúst Kristinn Arnlaugsson
Hi,
Maybe this subject has come up before but here it goes.
Im using c# in asp.net and im connecting to ldap server to retrieve some
properties from it, some properties work ok but for others i get the error
mentioned in the subject line, im using DirectoryService and here is the
code.
I add 3 properties, cn wich is not multi value, mail wich is and objectClass
is multi also, objectClass is the one that generates the error(when i take
the try catch out).
**Code Start**
DirectorySearcher searcher = new DirectorySearcher();
searcher.SearchRoot = new DirectoryEntry(LDAP://someserver/cn=somewhere);
searcher.SearchScope = SearchScope.Subtree;
searcher.Filter = "(uid=some)";
searcher.PropertiesToLoad.Add("cn");
searcher.PropertiesToLoad.Add("mail");
searcher.PropertiesToLoad.Add("objectClass");
SearchResultCollection results = searcher.FindAll();
foreach(SearchResult result in results)
{
Response.Write("mail=" + result.Properties["mail"][0] + "<br>");
if (result.Properties["mail"].Count > 1)
{
for (int i = 0;i < result.Properties["mail"].Count;i++)
{
Response.Write("mail=" + result.Properties["mail"] + "<br>");
}
}
else
{
Response.Write("mail=" + result.Properties["mail"][0] + "<br>");
}
try
{
if (result.Properties["objectClass"].Count > 1)
{
for (int i = 0;i < result.Properties["objectClass"].Count;i++)
{
Response.Write("objectClass=" +
result.Properties["objectClass"].ToString() + "<br>");
}
}
else
{
Response.Write("objectClass=" +
result.Properties["objectClass"][0].ToString() + "<br>");
}
}
catch
{
Response.Write("Couldnt write objectClass Property<br>");
}
}
**Code End**
Any help appreciated.
Best Regards
Agust
Maybe this subject has come up before but here it goes.
Im using c# in asp.net and im connecting to ldap server to retrieve some
properties from it, some properties work ok but for others i get the error
mentioned in the subject line, im using DirectoryService and here is the
code.
I add 3 properties, cn wich is not multi value, mail wich is and objectClass
is multi also, objectClass is the one that generates the error(when i take
the try catch out).
**Code Start**
DirectorySearcher searcher = new DirectorySearcher();
searcher.SearchRoot = new DirectoryEntry(LDAP://someserver/cn=somewhere);
searcher.SearchScope = SearchScope.Subtree;
searcher.Filter = "(uid=some)";
searcher.PropertiesToLoad.Add("cn");
searcher.PropertiesToLoad.Add("mail");
searcher.PropertiesToLoad.Add("objectClass");
SearchResultCollection results = searcher.FindAll();
foreach(SearchResult result in results)
{
Response.Write("mail=" + result.Properties["mail"][0] + "<br>");
if (result.Properties["mail"].Count > 1)
{
for (int i = 0;i < result.Properties["mail"].Count;i++)
{
Response.Write("mail=" + result.Properties["mail"] + "<br>");
}
}
else
{
Response.Write("mail=" + result.Properties["mail"][0] + "<br>");
}
try
{
if (result.Properties["objectClass"].Count > 1)
{
for (int i = 0;i < result.Properties["objectClass"].Count;i++)
{
Response.Write("objectClass=" +
result.Properties["objectClass"].ToString() + "<br>");
}
}
else
{
Response.Write("objectClass=" +
result.Properties["objectClass"][0].ToString() + "<br>");
}
}
catch
{
Response.Write("Couldnt write objectClass Property<br>");
}
}
**Code End**
Any help appreciated.
Best Regards
Agust