Hello folks, I have been liking what I find with using PrincipalContext and UserPrincipal. However, what I want to do is load all AD attributes into an ArrayList and feed that into a data table to populate a detailsview control. However, I am stumped; I
simply cannot figure out how to make this work. I would like to pass a saMAccountName to the query, then ask AD to return all user properties and their corresponding values. Here is my code at this point.
{
// TODO: Add panel that displays AD Details about selected PIN
LinkButton lnk = (LinkButton)sender;
string domainName = ddlDomainName.SelectedValue.ToString();
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, lnk.Text.ToString());
DirectoryEntry up_User = (DirectoryEntry)user.GetUnderlyingObject();
DirectorySearcher deSearch = new DirectorySearcher(up_User);
SearchResultCollection results = deSearch.FindAll();
int i = 0;
if (results != null && results.Count > 0)
{
DataTable dt = new DataTable();
ResultPropertyCollection rpc = results[0].Properties;
dt.Columns.Add("PropName");
dt.Columns.Add("PropValue");
foreach (string rp in rpc.PropertyNames)
{
// Property name rp.ToString();
// property value rpc[rp][0].ToString();
i++;
}
dvADPinDetails.DataSource = dt;
dvADPinDetails.DataBind();
pnlADPinDetails.Visible = true;
pnlGroupMembers.Visible = false;
}
}
I am thinking about using a gridview for this purpose. Any ideas?
All-Star
35218 Points
9955 Posts
Moderator
How to get all AD attributes listed using UserPrincipal and PrincipalContext
Nov 07, 2017 05:38 PM|bbcompent1|LINK
Hello folks, I have been liking what I find with using PrincipalContext and UserPrincipal. However, what I want to do is load all AD attributes into an ArrayList and feed that into a data table to populate a detailsview control. However, I am stumped; I simply cannot figure out how to make this work. I would like to pass a saMAccountName to the query, then ask AD to return all user properties and their corresponding values. Here is my code at this point.
I am thinking about using a gridview for this purpose. Any ideas?
All-Star
35218 Points
9955 Posts
Moderator
Re: How to get all AD attributes listed using UserPrincipal and PrincipalContext
Nov 07, 2017 07:22 PM|bbcompent1|LINK
Never mind, I figured it out on my own. This is what I ended up doing: