Solved

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

Posted on 2013-12-05
6
399 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
  • 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now