Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I am using window authentication in application. Here is some requirement to access all groups from domain name(retail.abg.com), & IP address is 10.557.847.55.
I am using light weight directory access protocol. my code throw error like
The server is not operational.

my code is given below.

C#
public List<string> ListGroups()
       {
           List<string> grp = new List<string>();
           string LDAP = "LDAP://";
           DirectoryEntry objADAM = default(DirectoryEntry);
           DirectoryEntry objGroupEntry = default(DirectoryEntry);
           DirectorySearcher objSearchADAM = default(DirectorySearcher);
           SearchResultCollection objSearchResults = default(SearchResultCollection);
           SearchResult myResult = null;
           try
           {
               objADAM = new DirectoryEntry(LDAP + "retail.abg.com");
               objADAM.RefreshCache();
               objSearchADAM = new DirectorySearcher(objADAM);
               objSearchADAM.Filter = "(&(objectClass=group))";
               objSearchADAM.SearchScope = SearchScope.Subtree;
               objSearchResults = objSearchADAM.FindAll();

               // Enumerate groups

               //fileGroups.AutoFlush = true;
               if (objSearchResults.Count != 0)
               {
                   foreach (SearchResult objResult in objSearchResults)
                   {
                       myResult = objResult;
                       objGroupEntry = objResult.GetDirectoryEntry();
                       grp.Add(objGroupEntry.Name);
                   }


               }
               else
               {
                   throw new Exception("No groups found");
               }
           }

           catch (Exception e)
           {
               throw new Exception(e.Message);
           }

           return grp;
       }



please help

Thanks
Ganu
Posted
Updated 18-Oct-12 2:21am
v2

 
Share this answer
 
C#
UserPrincipal current_user = UserPrincipal.Current;

            PrincipalContext current_context = current_user.Context;

            PrincipalContext ctx = new PrincipalContext(ContextType.Machine, "10.200.202.89");

            GroupPrincipal qbeUser = new GroupPrincipal(ctx);

            Principal userOrGroup = qbeUser as Principal;

            userOrGroup.Name = "*";

            PrincipalSearcher searcher = new PrincipalSearcher(userOrGroup);

            List<string> AllGroups = new List<string>();


            foreach (Principal found in searcher.FindAll())
            {
                if (found is GroupPrincipal)
                {

                    AllGroups.Add(found.Name);
                }
            }

            return AllGroups;


        }</string></string>
 
Share this answer
 
v2
Comments
I.explore.code 18-Oct-12 8:24am    
If this is not meant to be a solution, please post this as a comment to solution 1 otherwise, mark your question as "solved" and close this thread.

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