Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Active Directory access

Active Directory access

Scheduled Pinned Locked Moved C#
helpwindows-adminregexjson
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Talal Sultan
    wrote on last edited by
    #1

    Hi, I have a small windows application that connects to the local directory and retrieves the list of users. Then, it is possible to display the data of the user by clicking on a button. I use LDAP://DomainName to connect and things "seem" to be working fine. I manage to get the different data of the user I select (name, country, address, email, phone etc...) however I am having a problem with the "memberof" property. For some users, I am able to retrieve the list of groups he belongs to but for other users the property returns an empty collection. I am using the following piece of code: SearchResultCollection src = ds.FindAll(); SearchResult sr = src[0]; // I am filtering per username so only one match possible ResultPropertyValueCollection memberOf = sr.Properties["memberOf"]; // this sometimes returns zero items ResultPropertyValueCollection givenName = sr.Properties["givenName"]; ResultPropertyValueCollection lastName = sr.Properties["sn"]; ResultPropertyValueCollection email = sr.Properties["mail"]; ResultPropertyValueCollection address = sr.Properties["homePostalAddress"]; ResultPropertyValueCollection zip = sr.Properties["postalCode"]; ResultPropertyValueCollection country = sr.Properties["co"]; ResultPropertyValueCollection title = sr.Properties["title"]; ResultPropertyValueCollection city = sr.Properties["l"]; ResultPropertyValueCollection state = sr.Properties["st"]; ResultPropertyValueCollection phone = sr.Properties["telephoneNumber"]; ResultPropertyValueCollection otherPhone = sr.Properties["otherTelephone"]; ResultPropertyValueCollection fax = sr.Properties["facsimileTelephoneNumber"]; Then I filter the memberof collection like this: foreach (object role in memberOf) { string[] roleItems = role.ToString().Split(','); foreach (string temp in roleItems) { int i = temp.IndexOf("CN="); if (i >= 0) // found string { listGroups.Items.Add(temp.Substring(3)); } } } This will give me the group name. I have tried displaying the whole "role" string without parsing, I thought maybe my parsing was not complete, but I didn't get anything either. I am new in Active Directory stuff and I have no idea if there is another way to do things. Any help would be greatly appreciated. Talal

    "Progra

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups