Workaround for UserProfileManager in SharePoint Online (O365-S)

UserProfileManager and AudienceManager is not available in SharePoint sandbox.

Workaround: In order to fetch fetch user profile properties we will have to sync user profile properties to SiteUserInfoList which is a hidden list and fetch profile properties from this list. User profile properties which are replicable can be synchronized to this list. To check if a property is replicable or not we can edit property in UPSA and look for replicable attribute.

Sample code to access SiteUserInfoList

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();

       }

}

 

SharePoint Online Steps to set the Property Replicable

Step 1: Open SharePoint Online Admin portal and select Manage User Profiles

Note: Only SharePoint Online Administrator will have access to the administration center

image

 

Step 2: Under People section select Manage User Properties

image

 

Step 3: Select the property which you would like to sync, Edit the property

image

Step 4: Under Policy Settings section check Replicable property.

Note: Synchronization would take some time before it appears in the SiteUserInfoList

image

Comments

  • Anonymous
    May 22, 2014
    hi, thanks for your post., can it be used for custom fields ?

  • Anonymous
    October 10, 2014
    You can sync custom AD attributes to custom user profile properties in SharePoint Online with the BulkUserProfileUpdater found here:  github.com/.../Core.BulkUserProfileUpdater.

  • Anonymous
    October 10, 2014
    You can sync custom AD attributes to custom user profile properties in SharePoint Online using the BulkUserProfileUpdater found here:  github.com/.../Core.BulkUserProfileUpdater