I'm retrieving user profiles data from SharePoint user profile.
Its working fine.
I have SharePoint site http://pc5 and user with login name pc5\akshay for this user I'm able to get data from user profile.
But I have another user with login name SHAREPOINT\system, and I'm unable to get user data from user profile for this user .
using (SPWeb web = site.OpenWeb())
{
try
{
SPUser user = SPContext.Current.Web.CurrentUser;
SPUser CurrentUser = user;
var userLoginName = CurrentUser.LoginName;
SPServiceContext serviceContext = SPServiceContext.GetContext(site);
var profileManager = new UserProfileManager(serviceContext);
String[] breakApart = userLoginName.Split('|');
var accountName = breakApart[1];
var userProfile = profileManager.GetUserProfile(accountName);
Profile = userProfile;
var Department = userProfile["Department"].Value != null
? userProfile["Department"].Value.ToString()
: "";
var CurrentLocation = userProfile["SPS-DistinguishedName"].Value != null
? userProfile["SPS-DistinguishedName"].Value.ToString()
: "";
if (CurrentLocation != null)
{
String[] breakLocation = CurrentLocation.Split(',');
var OU = breakLocation[1];
String[] breakOU = OU.Split('=');
var location = breakOU[1];
}
}
Please help me with this