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


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 :


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.