Solved

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

Posted on 2013-12-05
6
416 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
Give Your Engineering Team a Productivity Boost

Learn why container technology is so powerful and how it can provide your team with productivity gains and other benefits.

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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:…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

626 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