Linkedin Twitter Youtube Email

A keystone to social computing using the Microsoft stack

The user profile database in SharePoint is a keystone to social computing using the Microsoft stack. We store information about users in our organization, communities or members of external sites in the user profile database.

Keystone to social using MS

Earlier today I was asked for sample code to access the user store. I often use the code below in presentations to demonstrate how we programmatically access information about users in the profile store. If we need to access user profiles from external applications we should use the SharePoint web services.

namespace UserProfilesSample 

{ 

    class Program 

    { 

        static void Main(string[] args) 

        { 

 

            using (SPSite site = new SPSite("http://SharePoint2007")) 

            { 

                ServerContext context = 

                    ServerContext.GetContext(site); 

                UserProfileManager profileManager = new UserProfileManager(context); 

 

                string userName = @"MyDomainAdministrator"; 

                Console.WriteLine("All Profiles:"); 

                foreach (UserProfile p in profileManager) 

                { 

                    Console.WriteLine("{0} : {1}", p.ID, p.MultiloginAccounts[0]); 

                } 

                Console.WriteLine("--"); 

                if (profileManager.UserExists(userName)) 

                { 

                    UserProfile profile = profileManager.GetUserProfile(userName);                 

                    Console.WriteLine("Found User Profile {0}", profile.ID); 

                    Console.WriteLine("tPersonal Site: {0} ({1})", 

                        profile.PersonalSite.RootWeb.Title, 

                        profile.PersonalSite.Url);                  

                } 

                else 

                { 

                    Console.WriteLine("No account found for " + userName); 

                } 

 

                Console.ReadLine(); 

 

            } 

        } 

 

    } 

}

twitter-bird-2

 

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *

Video and Streams

demo_image-5
#Microsoft​ #MSFTinHealth

Microsoft Cloud for Healthcare overview

X