Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am using sp2010. I get the current user from the context. And I would like to check if it is equal to the creator of an list item. But the code says it is not equal. Why? Is there some other solution to equal 2 spusers?

// check if current user is creator
SPUser creator = new SPFieldUserValue(web, this.ListItem["Author"].ToString()).User;
SPUser currentUser = SPContext.Current.Web.CurrentUser;
CurrentUserIsExpertiseCreator = creator.Equals(currentUser);
share|improve this question

4 Answers 4

try this:

            SPUser creator = new SPFieldUserValue(web, this.ListItem["Author"].ToString()).User;
            SPUser currentUser = SPContext.Current.Web.CurrentUser;
            CurrentUserIsExpertiseCreator = creator.Name.Equals(currentUser.Name);

instead of comparing the spuser object compare against the name (string)

or

           CurrentUserIsExpertiseCreator = creator.Name.CompareTo(currentUser.Name);
share|improve this answer

You can also compare their id.

share|improve this answer
    
While this may theoretically answer the question, we prefer inclusion of the essential parts of the answer here, for example a line or two of code to show how this would be done. Thanks. [mod] –  SPDoctor Mar 7 '13 at 12:21

I have fix it to compare the SID id from both spuser objects.

share|improve this answer
up vote 1 down vote accepted

This is the answer in code:

 SPUser creator = new SPFieldUserValue(web, this.ListItem["Author"].ToString()).User;
                                SPUser currentUser = SPContext.Current.Web.CurrentUser;
                                CurrentUserIsExpertiseCreator = creator.Sid.Equals(currentUser.Sid);
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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