Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top