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 user user1 (which is also the user of the app pool of SharePoint, so when I log on with user user1 it says "Welcome System Account").

In my code, i want to test if a file is checked out by user1, so the result of the following:

file.CheckedOutBy.LoginName.ToLower() == userName.ToLower())

is always false (which is not correct). CheckedOutBy value is "SharePoint System" while username value is "user1".

How can I resolve this?

share|improve this question
add comment

3 Answers

Your best option is to not log in as the SharePoint farm account.

If you have to log in with this account, you could try the following.

SPUser user = myWeb.EnsureUser(userName);

if (file.CheckedOutBy.Id == user.Id)
{
    // your code here
}

Things to note Note:

  • myWeb is an SPWeb, you likely have one open already, if not you should be able to work backwards from the SPFile object.
  • I can't the format that EnsureUser needs the username to be in, you may need to append the domain? and it May throw exceptions if the user can't be found in your Auth Provider (AD? Forms?)
share|improve this answer
add comment

Thanks all, this is how i solved it:

file.CheckedOutBy.LoginName.ToLower() == web.CurrentUser.LoginName.ToLower() giving sharepoint\system on both sides, which is correct

share|improve this answer
add comment

try this

CheckedOutBy.LoginName.equals(SPContext.Current.Web.CurrentUser.LoginName)

share|improve this answer
add comment

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.