Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts

    iterating through AD property values

    ok, so this is what im using so far. ( Im learning, bear with me) It lists all the propertynames, I need to list the names and then also the values of those properties
    GetUser(user) returns a valid DirectoryEntry Object, btw.

    oh yeah, C#, asp.net 4.0

    Code:
            protected void Button1_Click(object sender, EventArgs e)
            {
                Literal1.Text = "";
                string user = User.Identity.Name.ToString().Split("\\".ToCharArray())[1];
                           foreach (string strAttrName in GetUser(user).Properties.PropertyNames)
                {
                    
                    Literal1.Text += strAttrName+"<br />";
                }
                
    
            }
    I can access individual properties, but I want to iterate through all of them so I can just exclude a few and keep the rest, etc..

    I am doing this using :

    Code:
     Literal1.Text += "<br />" + GetUser(user).Properties["mail"][0];

  • #2
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    ok, found a solution:

    Code:
               foreach (string propName in GetUser(user).Properties.PropertyNames)
                {
                    foreach (object value in GetUser(user).Properties[propName])
    
                       Literal1.Text += "prop = "+propName+" val="+ value+"<br />";
                }
    Im curious, how would I declare GetUser(user) as a variable so it only runs once ( on a button click)and caches the info?

  • #3
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    alykins? anyone?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •