1

I'm trying to get the current users office from the profile service.

I've managed to get name and emails for the current user but the office does not seem to be an available option

2
  • How are you trying to get the office location? C# / JS? CSOM/SSOM?
    – Akhoy
    Aug 3, 2015 at 9:07
  • C# The following is what has worked for a users email and name 'code' SPContext.Current.Web.CurrentUser
    – Lee Watson
    Aug 3, 2015 at 12:41

1 Answer 1

0

I think this might be what you are looking for : https://msdn.microsoft.com/en-us/library/office/jj163142.aspx (SSOM)

It uses the class UserProfileManager from Microsoft.Office.Server.UserProfiles namespace. Once you get the UserProfile object with GetUserProfile, check UserProfile.Properties.

Ex:

UserProfileManager upm = new UserProfileManager(SPServiceContext.Current);
UserProfile up = upm.GetUserProfile(SPContext.Current.Web.CurrentUser.LoginName);

For those interested :

EDIT : To get more properties, you have to use the PeopleManager. I haven't figured if it can be used with the SSOM, but I managed to get the Office property using the Client OM.

using Microsoft.SharePoint.ClientRuntime 
using Microsoft.SharePoint.Client.UserProfiles;
using Microsoft.SharePoint.Client;
...
 ClientContext clientContext = new ClientContext(site.Url);
 PeopleManager pmgr = new PeopleManager(clientContext);
 PersonProperties prop = pmgr.GetPropertiesFor(targetAccountName);
 clientContext.Load(prop, p => p.UserProfileProperties);
 clientContext.ExecuteQuery();
 Console.WriteLine(prop.UserProfileProperties["Office"]);
...
4
  • Thanks for the answer however I am running sharepoint 2010 not 2013
    – Lee Watson
    Aug 5, 2015 at 9:07
  • The namespace is also available for SharePoint 2010, if you are using C#
    – JayHell
    Aug 5, 2015 at 11:07
  • I have used this elsewhere, however it seems to be restricted to login name, email and a couple of other things that are not needed
    – Lee Watson
    Aug 5, 2015 at 14:13
  • Check my edit. I tried to use the PeopleManager class, but I get an exception saying the context is required. There is no constructor with parameters...
    – JayHell
    Aug 5, 2015 at 15:27

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.