I have a web part I am trying to build and I need the UserProfilePropertiesForUser value for EmployeeNumber which is a custom field. To get this i am using SPContext.Current.Web.CurrentUser for the current user and SPContext.Current.Site.Url
to get the current URL. I am using PeopleManager peopleManager = new PeopleManager(clientContext); string[] profilePropertyNames = new string[] { "EmployeeNumber" }; to get the employeeNumber
I do not know if this is the correct way to go about this or not but its all i could come up with. The problem I am having is
PeopleManager' is an ambiguous reference between 'Microsoft.SharePoint.Client.UserProfiles.PeopleManager'
and 'Microsoft.Office.Server.UserProfiles.PeopleManager. Is there a way to get around this?
The problem is with these two references.
Microsoft.Office.Server.UserProfiles or
Microsoft.SharePoint.Client.UserProfiles
Any help would be appreciated.
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;
using System.Collections.Generic;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.UserProfiles;
using Microsoft.Office.Server;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.Office.Server.Administration;
using Microsoft.SharePoint.WebControls;
namespace ABC.ABC
{
public partial class ABCUserControl : UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
SPUser currentUser = SPContext.Current.Web.CurrentUser;
string currentServer = SPContext.Current.Site.Url;
string currenturl = HttpContext.Current.Request.Url.ToString();
const string serverUrl = "currentServer";
const string targetUser = "currentUser";
ClientContext clientContext = new ClientContext(serverUrl);
// Get the PeopleManager object.
PeopleManager peopleManager = new PeopleManager(clientContext);
string[] profilePropertyNames = new string[] { "EmployeeNumber" };
UserProfilePropertiesForUser profilePropertiesForUser = new UserProfilePropertiesForUser(clientContext, targetUser, profilePropertyNames);
IEnumerable<string> profilePropertyValues = peopleManager.GetUserProfilePropertiesFor(profilePropertiesForUser);
// Load the request and run it on the server.
clientContext.Load(profilePropertiesForUser);
clientContext.ExecuteQuery();
// Iterate through the property values.
foreach (var value in profilePropertyValues)
{
Console.Write(value + "\n");
string a = value;
}
}
}
}
Thank You