0

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?

1

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?)
0

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

-1

try this

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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