2

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

1 Answer 1

7

System account is basically the Web application pool account user which you have passed during web application creation phase. You cannot find this user with account name "SharePoint\System" in User Profile.

This is the account which is used when you run your code in under elevated privileges by SPSecurity.RunWithElevatedPrivileges

Account name with "SharePoint\System" is not available in the Service. It's not recommended to use "SharePoint\System" account as end user purpose.

You should try with all other users except system account.

You can check for this user from Central Administration. Go to Central admin >> User Profile service >> go to Manage Profiles and here try to search user using "SharePoint\System" , you will find nothing. This means user with this account name is not available in the Service.

2
  • that make sense to me May 5, 2017 at 7:28
  • Kindly mark as accepted answer and up vote my answer if it's helpful to you.😊 May 6, 2017 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.