954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

C# AD - Strange problem when listing members of one group

I have a very strange problem...I have a function which works in 99/100 times...But unfortunately I have noticed one group which generates me some problems.
The worst thing is that I don't see anything special in it...name is nomral, I have access to list it...But my program doesn't return any results...It threat it as if it was empty...
But I know its not true:

String listGroupUsers(string Name)
        {
            try
            {
                SearchResult result;
                DirectorySearcher search = new DirectorySearcher();
                search.Filter = String.Format("(cn={0})", Name);
                search.PropertiesToLoad.Add("member");
                result = search.FindOne();
                if (result == null)
                {
                    search.Filter = String.Format("(samAccountName=" + Name + ")");
                    result = search.FindOne();
                    if (result == null)
                    {
                        tempreport1.Add("ERROR: Input name couldn't be found in AD");
                        return "ERROR: Input name couldn't be found in AD"; 
                    }
                }
                StringBuilder userList = new StringBuilder();
                if (result != null)
                {
                    for (int counter = 0; counter < result.Properties["member"].Count; counter++)
                    {
                        string user = (string)result.Properties["member"][counter];
                        string property = getproperty("LDAP://" + user, "displayname");
                        if (property=="No record found") // grupy nie maja display name - wiec jak sie na nich wywali ma wyciagnac win2000 name
                        {  
                        property = getproperty("LDAP://" + user, "samAccountName");
                        }
                        userList.Append(property);
                        userList.Append("\r\n");
                    }
                }
                tempreport1.AddRange(userList.ToString().Split(new string[] { "\r\n" }, StringSplitOptions.None).ToList());
                return userList.ToString();
            }
            catch (Exception)
            {
                return " ";
            }
        }


The most interesting thing is that the most important condition is fulfilled (23rd line):

if (result != null)

so there ARE results but...when I try to show any results with line:

result.Properties["member"][X]
X = any number

it returns null...

result.Properties["member"].Count


is 0..so the for loop in my program isn't launched at all... WHY?...I am really curious because that group count about 3000 members...

VasquezPL
Junior Poster
120 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

can it be a bug? because for me the code is very OK..

VasquezPL
Junior Poster
120 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: