Get User Profile

Here's the code to retrieve the UserProfile from User Profiles Service Application in Sharepoint 2010 by passing the account name


SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        using (SPSite site = new SPSite("SiteUrl"))
                        {
                            SPServiceContext context = SPServiceContext.GetContext(site);
                            UserProfileManager allProfiles = new UserProfileManager(context);
                            string loginName = @"DomainName\AccountName";
                            //Ex: TestDoamin\abc
                            //You can also use UserExists method to check
                            if (allProfiles.ResolveProfile(loginName).Length == 1)
                            {
                                UserProfile up = allProfiles.GetUserProfile(loginName);
                           
                             }
                        }
                    });

0 comments:

Post a Comment