Earlier i have given a customised solution to get the current user permissions in share point 2010.Here i will show how to get the user details from share point site using UserProfileManager class.Before going to get the profile details we need to check whether the user is valid or not.Then the resultant data will be assigned to user profile class and get account name into string
SPSite sps = SPContext.Current.Site; using (SPWeb spw = sps.OpenWeb()) { SPServiceContext spsc = SPServiceContext.GetContext(sps); UserProfileManager uprofile = new UserProfileManager(spsc); string useraccountname = SPContext.Current.Web.CurrentUser.LoginName; if (uprofile.UserExists(useraccountname)) { UserProfile Profileinfo = uprofile.GetUserProfile(useraccountname); if (!string.IsNullOrEmpty(Profileinfo["FirstName"].ToString())) { string AccountName = userProfile["FirstName"].ToString(); } } }
No comments:
Post a Comment