Solved

How do I display the Active Directory Groups in a List Box?

Posted on 2013-12-05
6
409 Views
Last Modified: 2013-12-05
Here are my events:

<%@ Import Namespace="System.DirectoryServices" %>

<script runat="server">

 public ArrayList Groups()
    {
        ArrayList groups = new ArrayList();
        foreach (System.Security.Principal.IdentityReference group in
            System.Web.HttpContext.Current.Request.LogonUserIdentity.Groups)
        {
            groups.Add(group.Translate(typeof
                (System.Security.Principal.NTAccount)).ToString());
        }
        return groups;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        dGroups.DataSource = Groups();
        dGroups.DataBind();
    }

Open in new window


My question is - how do I display the results in a list box?  I can not seem to get all my settings/preferences correct:

<asp:DropDownList ID="dGroups" runat="server"  DataTextField="ArrayList" DataValueField="Department" onselectedindexchanged="" 
        AutoPostBack="True" AppendDataBoundItems="True">
        <asp:ListItem Value="0">Select</asp:ListItem>
      </asp:DropDownList>

Open in new window

0
Comment
Question by:programmher
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 22

Accepted Solution

by:
plusone3055 earned 250 total points
ID: 39698990
0
 

Author Comment

by:programmher
ID: 39699036
So, if I want the Active Directory Groups to display in a listbox in the body of my form, I do not need to reference the event?
0
 
LVL 22

Expert Comment

by:plusone3055
ID: 39699044
its not necessary :)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:programmher
ID: 39699109
Ok.  I am working on including this on my form.
0
 
LVL 22

Expert Comment

by:plusone3055
ID: 39699121
Excellent :)
Enjoy and if it works for you please award points.
Happy Coding
0
 

Author Comment

by:programmher
ID: 39699136
I have added the code to my form.  No errors, but the list box/drop down list with the Active Directory groups is not displaying on my form.  Here is what I added:
 public ArrayList Groups()
    {
        ArrayList groups = new ArrayList();
        foreach (System.Security.Principal.IdentityReference group in
            System.Web.HttpContext.Current.Request.LogonUserIdentity.Groups)
        {
            groups.Add(group.Translate(typeof
                (System.Security.Principal.NTAccount)).ToString());
        }
        return groups;
    }
    public ArrayList AttributeValuesMultiString(string attributeName,
     string objectDn, ArrayList valuesCollection, bool recursive)
    {
        DirectoryEntry ent = new DirectoryEntry(objectDn);
        PropertyValueCollection ValueCollection = ent.Properties[attributeName];
        IEnumerator en = ValueCollection.GetEnumerator();

        while (en.MoveNext())
        {
            if (en.Current != null)
            {
                if (!valuesCollection.Contains(en.Current.ToString()))
                {
                    valuesCollection.Add(en.Current.ToString());
                    if (recursive)
                    {
                        AttributeValuesMultiString(attributeName, "LDAP://" +
                        en.Current.ToString(), valuesCollection, true);
                    }
                }
            }
        }
        ent.Close();
        ent.Dispose();
        return valuesCollection;
    }

    public ArrayList Groups(string userDn, bool recursive)
    {
        ArrayList groupMemberships = new ArrayList();
        return AttributeValuesMultiString("memberOf", userDn,
            groupMemberships, recursive);
    }

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question