0

How to get the user profile data in share point sandbox Visual webapart? I am using Spservicecontext class,But this class not available in sandbox solution so how can i get the user Details

1 Answer 1

0

You cannot access user profile in sandbox solution because SPUserProfileManager is not allowed to be used inside the sandbox solution. For a workaroundyYou can use following code to get user profile list:

private SPList userInformationList = null;

private SPUser user = null;

private SPListItem userItem = null;

using (SPSite site = new SPSite(SPContext.Current.Web.Url))

{ 
       using (SPWeb web = site.OpenWeb()) 
       { 
               // Instantiates the User Information List  
               userInformationList = SPContext.Current.Web.SiteUserInfoList;

               // Get the current user  
               user = web.EnsureUser(web.CurrentUser.Name);

               // The actual User Information is within this SPListItem  
               userItem = userInformationList.Items.GetItemById(user.ID);

              string officeLocation = userItem["Office"].ToString();

       }

}

You can also check :

http://social.msdn.microsoft.com/forums/sharepoint/en-US/fc0f1fa8-0f2b-42f4-8364-d48ed344c3fd/getting-logged-in-user-details-in-sandbox-solutions-from-oob

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.