Monday, March 13, 2017

Compare SPUser objects in SP code


I have to compare the User value in the Assigned To Field of the List with the other User value.
Here is the exact code that will do this.

SPUser spUser = GetSPUserOne();
SPUser spPrevUser = GetSPUserTwo();

For Windows Authentication This will do

if(spUser.Sid.Equals(spPrevUser.Sid))
{
…..
}

For FBA you have to follow this

if(spUser.UserToken.CompareUser(spPrevUser.UserToken))
{
…..
}

No comments:

Post a Comment