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. Visual Basic
  4. ADSI VB.Net Get User and Update

ADSI VB.Net Get User and Update

Scheduled Pinned Locked Moved Visual Basic
csharpcomannouncement
3 Posts 2 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.
  • J Offline
    J Offline
    japel
    wrote on last edited by
    #1

    Hi All I need to write an application that checks A CSV file for a user and if they exist update a corresponding number into their "primaryTELEX" attribute. CSV File ================== john smith 1234 jane jones 3421 ================== I have found articles with examples in C but am having trouble converting the syntax over to VB.Net (Never worked in C) The two examples I found are. Find User: The following sample code uses the FindOne method of the DirectorySearcher class to find the same user we authenticated a moment ago. We will limit the properties that are retrieved during the search. DirectoryEntry entry = new DirectoryEntry("LDAP://dev.codeguru.com"); try { DirectorySearcher search = new DirectorySearcher(entry); search.Filter = "(SAMAccountName=administrator)"; search.PropertiesToLoad.Add("Name"); search.PropertiesToLoad.Add("displayName"); SearchResult result = search.FindOne(); if( result != null ) { Console.WriteLine("User found"); foreach( string key in result.Properties.PropertyNames ) { // Each property contains a collection of its own // that may contain multiple values foreach( Object propValue in result.Properties[key] ) { Console.WriteLine(key + " = " + propValue); } } } else { Console.WriteLine("User not found"); } } catch( Exception ex ) { throw new Exception("User not authenticated: " + ex.Message); } Console.ReadLine(); Update Atribute: try { string path = "LDAP://CN=Users,DC=dev,DC=codeguru,DC=com"; DirectoryEntry entry = new DirectoryEntry(path, "dev.codeguru.com\\administrator", "password"); DirectorySearcher search = new DirectorySearcher(entry); search.Filter = "(SAMAccountName=testuser)"; SearchResult result = search.FindOne(); DirectoryEntry user = result.GetDirectoryEntry(); user.Properties["description"].Value = "New description for user"; user.CommitChanges(); } catch( Exception exception ) { Console.WriteLine( exception.Message ); } Looking for any aritcal that does this in VB, (examles would be great... When people make you see red, be thankful your not colour blind.

    H 1 Reply Last reply
    0
    • J japel

      Hi All I need to write an application that checks A CSV file for a user and if they exist update a corresponding number into their "primaryTELEX" attribute. CSV File ================== john smith 1234 jane jones 3421 ================== I have found articles with examples in C but am having trouble converting the syntax over to VB.Net (Never worked in C) The two examples I found are. Find User: The following sample code uses the FindOne method of the DirectorySearcher class to find the same user we authenticated a moment ago. We will limit the properties that are retrieved during the search. DirectoryEntry entry = new DirectoryEntry("LDAP://dev.codeguru.com"); try { DirectorySearcher search = new DirectorySearcher(entry); search.Filter = "(SAMAccountName=administrator)"; search.PropertiesToLoad.Add("Name"); search.PropertiesToLoad.Add("displayName"); SearchResult result = search.FindOne(); if( result != null ) { Console.WriteLine("User found"); foreach( string key in result.Properties.PropertyNames ) { // Each property contains a collection of its own // that may contain multiple values foreach( Object propValue in result.Properties[key] ) { Console.WriteLine(key + " = " + propValue); } } } else { Console.WriteLine("User not found"); } } catch( Exception ex ) { throw new Exception("User not authenticated: " + ex.Message); } Console.ReadLine(); Update Atribute: try { string path = "LDAP://CN=Users,DC=dev,DC=codeguru,DC=com"; DirectoryEntry entry = new DirectoryEntry(path, "dev.codeguru.com\\administrator", "password"); DirectorySearcher search = new DirectorySearcher(entry); search.Filter = "(SAMAccountName=testuser)"; SearchResult result = search.FindOne(); DirectoryEntry user = result.GetDirectoryEntry(); user.Properties["description"].Value = "New description for user"; user.CommitChanges(); } catch( Exception exception ) { Console.WriteLine( exception.Message ); } Looking for any aritcal that does this in VB, (examles would be great... When people make you see red, be thankful your not colour blind.

      H Offline
      H Offline
      HL_SUB
      wrote on last edited by
      #2

      I understand that you wish to manipulate a CSV file. I think the best way to deal with CSV files is to refer to them like refering to databases. Using the following link you can learn how to connect to the CSV file as a database and all you need is some knowledge in SQL queries. http://weblogs.asp.net/fmarguerie/archive/2003/10/01/29964.aspx HL -- modified at 6:26 Sunday 12th March, 2006

      J 1 Reply Last reply
      0
      • H HL_SUB

        I understand that you wish to manipulate a CSV file. I think the best way to deal with CSV files is to refer to them like refering to databases. Using the following link you can learn how to connect to the CSV file as a database and all you need is some knowledge in SQL queries. http://weblogs.asp.net/fmarguerie/archive/2003/10/01/29964.aspx HL -- modified at 6:26 Sunday 12th March, 2006

        J Offline
        J Offline
        japel
        wrote on last edited by
        #3

        The CSV file is no problem it is the query to LDAP and how to find user than update that is what I am having problems with. I have not work with LDAP for the Directory Service in .net and am fairly new to the whole dev world.. Thanks for your input thow... When people make you see red, be thankful your not colour blind.

        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