How to get user information into a list?
-
mercoledì 28 marzo 2012 01:54
Hello Friends,
I intend to display my company's user information from the Active Directory into a contacts list. Please suggest to achieve this.
I guess I need to use the user profile synchronization service first, but can you explain the steps in detail?
Thanks & Regards, Chandra Shekhar
Tutte le risposte
-
mercoledì 28 marzo 2012 03:40
User profile synchronization service just help you sync some properties from AD to SharePoint.
In SPUser, you can find displayname, alias, email address and so on. But also, you can find these properties directly from AD.
http://www.ianatkinson.net/computing/adcsharp.htm
using System; using System.Text; using System.DirectoryServices; namespace activeDirectoryLdapExamples { class Program { static void Main(string[] args) { Console.Write("Enter user: "); String username = Console.ReadLine(); try { // create LDAP connection object DirectoryEntry myLdapConnection = createDirectoryEntry(); // create search object which operates on LDAP connection object // and set search object to only find the user specified DirectorySearcher search = new DirectorySearcher(myLdapConnection); search.Filter = "(cn=" + username + ")"; // create results objects from search object SearchResult result = search.FindOne(); if (result != null) { // user exists, cycle through LDAP fields (cn, telephonenumber etc.) ResultPropertyCollection fields = result.Properties; foreach (String ldapField in fields.PropertyNames) { // cycle through objects in each field e.g. group membership // (for many fields there will only be one object such as name) foreach (Object myCollection in fields[ldapField]) Console.WriteLine(String.Format("{0,-20} : {1}", ldapField, myCollection.ToString())); } } else { // user does not exist Console.WriteLine("User not found!"); } } catch (Exception e) { Console.WriteLine("Exception caught:\n\n" + e.ToString()); } } static DirectoryEntry createDirectoryEntry() { // create and return new LDAP connection with desired settings DirectoryEntry ldapConnection = new DirectoryEntry("rizzo.leeds-art.ac.uk"); ldapConnection.Path = "LDAP://OU=staffusers,DC=leeds-art,DC=ac,DC=uk"; ldapConnection.AuthenticationType = AuthenticationTypes.Secure; return ldapConnection; } } }
Regards, Nighting Liu
- Proposto come risposta Aviw_ mercoledì 28 marzo 2012 06:36
- Contrassegnato come risposta Xue-Mei Chang-MSFTModerator martedì 3 aprile 2012 09:45
-
mercoledì 28 marzo 2012 17:51
Hello,
Thank you for the information. I was wondering is there any OOTB approach to get that information as I am not allowed to deploy code based solutions.
Please suggest
Thanks & Regards, Chandra Shekhar
-
venerdì 30 marzo 2012 07:49Moderatore
Hi,
As far as I know, there is no OOTB way to get the user information in a list, you should get it programmatically.
You can also refer to:http://www.fewlines4biju.com/2011/04/how-to-get-userprofile-information.html
Xue-mei Chang
TechNet Community Support
- Proposto come risposta Margriet Bruggeman venerdì 30 marzo 2012 07:51
- Contrassegnato come risposta Xue-Mei Chang-MSFTModerator martedì 3 aprile 2012 09:45

