As far as I know, there are no made-in method to sort the property name.
If you want to sort the property by property name, I suggest you could use directory to achieve your requirement.
You could firstly read the property name as directory name and the value as the directory value.
Then you could use convert the directory key to list and use Sort method to sort the value.
More details, you could refer to below codes:
SearchResult result = search.FindOne();
var re = result.Properties.PropertyNames;
var dictionary = new Dictionary<string, string>();
foreach (var item in re)
{
dictionary.Add((string)item, (String)result.Properties[(string)item][0]);
}
var list = dictionary.Keys.ToList();
list.Sort();
// Loop through keys.
foreach (var key in list)
{
Console.WriteLine("{0}: {1}", key, dictionary[key]);
}
Console.ReadLine();
Best Rregards,
Brando
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
7 Points
26 Posts
Active Directory sort propertyname
Apr 26, 2018 02:34 PM|sh|LINK
I am getting many properties for the AD record in C#. I list out these values as ( partial list below)
samaccounttype = 8053
lastlogon = 131692205645025544
homedrive = C:
displayname = Steve
cn = me
... etc
I would like to sort on property name. so the output would look like this:
cn = me
displayname = Steve
homedrive = C:
lastlogon = 131692205645025544
samaccounttype = 8053
etc
I see how to sort on example "displayname". Not sure how sort on ALL property name.
SortOption sortedResults = new SortOption();
sortedResults.PropertyName = "displayname";
TIA
Steve42
Star
9831 Points
3120 Posts
Re: Active Directory sort propertyname
Apr 27, 2018 05:41 AM|Brando ZWZ|LINK
Hi sh,
As far as I know, there are no made-in method to sort the property name.
If you want to sort the property by property name, I suggest you could use directory to achieve your requirement.
You could firstly read the property name as directory name and the value as the directory value.
Then you could use convert the directory key to list and use Sort method to sort the value.
More details, you could refer to below codes:
Best Rregards,
Brando
Member
7 Points
26 Posts
Re: Active Directory sort propertyname
Apr 29, 2018 04:42 PM|sh|LINK
THANKS! That was a big help.