View Full Version : iterating through AD property values

12-30-2011, 07:19 PM
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

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 :

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

12-30-2011, 07:33 PM
ok, found a solution:

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?

12-30-2011, 11:32 PM
alykins? anyone? :)