I have Requirement to Create WebPart that get Data from USer Profile of Current User in Office 365(SharePoint Online-SandBox).

is that Possible with SandBox Solution?

Thanks in Advance.

2 Answers 2


You can add a Script Editor Webpart and use the rest api to get the user profile details.

Below is a snippet which show you to get an instance of people manager using rest api

$.ajax({  url: "http://<site url>/_api/sp.userprofiles.peoplemanager",  type: "GET",headers: { "accept": "application/json;odata=verbose" },  success: successHandler, error: errorHandler});

On Success you can write your logic how you wanted to use the User profile data.

  • so,we can not do it by server side code.. Commented Jan 16, 2015 at 8:25
  • In SharePoint Online you cannot deploy farm solutions, Although you can also Create a SandBoxed Webpart and use the C# Client object model to use the user profile. Commented Jan 16, 2015 at 8:28
  • I had figured out with rest api. can u tell how to get Department from User Profile? Commented Jan 16, 2015 at 9:48
  • Do you want the department name for the logged in user or for any other user, Cause there are two ways and based on condition it is easy to use the approaches Commented Jan 16, 2015 at 10:44
  • i want it for current logged in user. Commented Jan 16, 2015 at 10:46

You can also create a sandbox Webpart and use the below code. Add the user profile dll and using Microsoft.SharePoint.Client.UserProfiles; in your code

const string serverUrl = "http://serverName/";  
        const string targetUser = "domainName\\userName";

        // Connect to the client context.
        ClientContext clientContext = new ClientContext(serverUrl);

        // Get the PeopleManager object and then get the target user's properties.
        PeopleManager peopleManager = new PeopleManager(clientContext);
        PersonProperties personProperties = peopleManager.GetPropertiesFor(targetUser);

        // Load the request and run it on the server.
        // This example requests only the AccountName and UserProfileProperties
        // properties of the personProperties object.
        clientContext.Load(personProperties, p => p.AccountName, p => p.UserProfileProperties);

        foreach (var property in personProperties.UserProfileProperties)
            Console.WriteLine(string.Format("{0}: {1}", 
                property.Key.ToString(), property.Value.ToString()));

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.