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
Step 2: Under People section select Manage User Properties
Step 3: Select the property which you would like to sync, Edit the property
Step 4: Under Policy Settings section check Replicable property.
Note: Synchronization would take some time before it appears in the SiteUserInfoList