I am trying get the Modified By column value. And I want to check my PeoplePicker control contains the value same as the Modified By column value.

I am stuck in the problem that Modified By column's value is System Account and that user is e.g. SPFarm and I am passing that SPFarm in my PeoplePicker control and trying to compare that both values are same or not.

But it is not working. When I get the value of Modified By column it returns "SharePoint\\System" and my PeoplePicker control returs "id|spfarm".

I am using SharePoint 2013...
How can I compare both fields...?

Any suggestions will be appreciated..! :)

  • 2
    Instead of comparing the LoginNames, compare the ID's. Commented Feb 17, 2014 at 14:13
  • @JPRoelofse I have tried to compare ID's but the ID which I am getting are different. I have user SPFarm as system account and same user I am passing in SPUser but both the id's I am getting are different. Is there any other way? I am using SharePoint 2013. Commented Feb 20, 2014 at 5:33

4 Answers 4


You can compare the token value of the account to determine if it is equal to the one of the system account. Note that in the following you get the SPSite object under elevated privileges and that comparing tokens only works when the actual account in SharePoint is already listed as the system account.

SPUser user = <<your code here>>
SPSite site = <<your code here>>
SPUserToken systemAccountToken = site.SystemAccount.UserToken;
bool userIsSystemAccount = user.UserToken.CompareUser(systemAccountToken);

Delving a bit deeper in the FarmCredentialManagement page in Central Administration site there is another way to get the actual user behind the SharePoint\\System account. The timer service in SharePoint runs under the Farm Account. Getting the ProcessIdentity for this service gives you direct access to the UserName of the Farm Account which you can compare with the user from your people picker.

SPTimerService timerservice = site.WebApplication.Farm.TimerService;
SPProcessIdentity pi = timerservice.ProcessIdentity;
string farmAccount = pi.UserName;
  • I tried your code but it is not working. My System user is spfarm and I am passing in SPUser is also spfarm. But both tokens I am getting is different. Commented Feb 20, 2014 at 4:53
  • Is it because I am using SharePoint 2013? Commented Feb 20, 2014 at 5:34
  • Hi Rahul, I edited my reply a bit. Can you check with the last part if that resolves the issue for you? You should be able to just compare the usernames like that.
    – Steven
    Commented Feb 24, 2014 at 8:40

You can compare the user ID with the SystemAccount.ID

Exemple :

SPUser yourUser = 'your code here';
if (yourUser.ID == web.Site.SystemAccount.ID)
  • I also have tried this before. But the ID are not same. I don't know why. Is there any other way?" Commented Feb 20, 2014 at 4:53

I'll take a wild guess here and assume you are comparing user under elevated privileges. To get "true" user, you have to get him from SPContext. Something like

int userID = SPContext.Current.Web.CurrentUser.ID;

To get SHAREPOINT/System account you can use following code

int systemID = SPContext.Current.Web.SystemAccount.ID;

Then simply compare both integers

if (userID == systemID){
  • CurrentUser.ID will work but I am fetching User from my list's Modified By column. So I need to compare User entered to my people picker control and list's modified by column. If modified by column contains System Account, it is not comparing both values. Commented Feb 20, 2014 at 8:27
  • @RahulGokani So, if I understand correctly, problem is if the list was modified by System account, you are not sure with what you should compare it?
    – StupidOne
    Commented Feb 20, 2014 at 9:34
  • Yes. For now I know that spfarm is my system account. But when I pass spfarm in people picker control it leaves no clue from that i can identify that it is system account. And when I login with spfarm my list's entries have system account in there column. Commented Feb 20, 2014 at 9:42
  • @RahulGokani Is this of any help?
    – StupidOne
    Commented Feb 20, 2014 at 12:34
  • No I can't do this. I have to do using code only. Commented Feb 20, 2014 at 12:43

In SharePoint 2013 there is a simple way to check if SPUser is System. After getting your SPUser object, check the {SPUserInstance}.UserToken.IsSystemAccount boolean property.

var list = GetMyList();
SPFieldUser flduser = (SPFieldUser)list.Fields[SPBuiltInFieldId.Author];
SPFieldUserValue fldTypeValue = (SPFieldUserValue)flduser.GetFieldValue(fieldValue.ToString());

var isSystem = fldTypeValue.User.UserToken.IsSystemAccount;

So you could check if SPUser of "Modified By" field and SPUser of the peoplepicker both are sistem accounts.

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.