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