Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi i am having a list of "ldap" path. i am reading a particular property after binding it into a directory entry. But for invalid path its throwing the server is not operational exception after some time. it causes the application freeze. so i need to conform about the entry exists or not before reading the property value. Is there any way to do this? waiting for helpful suggestions. Thanks.
Posted
Updated 6-Aug-13 2:13am
v2
Comments
ZurdoDev 6-Aug-13 8:14am    
What is a long time? This is due to a timeout issue. I am not sure, but you could probably configure the amount of time it waits before it assumes the path is invalid.
Selvakumar Gurusamy 6-Aug-13 8:24am    
the code is like this

public List<string> GetGuidLists(List<string> ldapPaths)
{
List<string> guids = new List<string>();

foreach (string path in ldapPaths)
{
if (!string.IsNullOrEmpty(path))
{
try
{
DirectoryEntry entry = new DirectoryEntry(path);
guids.Add(new Guid(entry.Properties["objectGuid"][0] as byte[]).ToString());
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}

return guids;
}
Jochen Arndt 6-Aug-13 8:37am    
Check if the path exists using the DirectoryEntry.Exists() method before trying to access non existing pathes.
Selvakumar Gurusamy 7-Aug-13 0:02am    
I did this also. its also take same time like reading a property from the invalid directory entry.
Jochen Arndt 7-Aug-13 3:40am    
If this takes the same time, you may move your code into another thread so that your main thread with the GUI is not blocked.

You may also try to use the DirectorySearcher class to check if the path exists. With this class you can specify a timeout value with the ClientTimeout property.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900