Office365-REST-Python-Client icon indicating copy to clipboard operation
Office365-REST-Python-Client copied to clipboard

How to know whether in SharePoint a file is checked in or not?

Open AniPetr opened this issue 3 years ago • 3 comments

Hello,

I work with different types of SP pages. On some pages files are checked in when they are uploaded. On the others files need to be checked in after they are uploaded.

How can I check whether a file is checked in or not?

AniPetr avatar Feb 16 '22 08:02 AniPetr

I believe that can be accomplished by accessing the properties on the file.

Get a file object: https://github.com/vgrem/Office365-REST-Python-Client/blob/master/examples/sharepoint/files/get_file_properties.py Not sure if there is a dedicated property that tells you if the file checked in, but you could check for a user:

  • access the file.checked_out_by_user property to return a user object.
  • or alternatively get it as a value via the properties dict on the file object: file.properties['CheckedOutByUser']

VdWWouter avatar Feb 18 '22 22:02 VdWWouter

When I print out properties, I see only the following ones:

  • CheckInComment
  • CheckOutType
  • ContentTag
  • CustomizedPageStatus
  • ETag
  • Exists
  • IrmEnabled
  • Length
  • Level
  • LinkingUri
  • LinkingUrl
  • MajorVersion
  • MinorVersion
  • Name
  • ServerRelativeUrl
  • TimeCreated
  • TimeLastModified
  • Title
  • UIVersion
  • UIVersionLabel
  • UniqueId

file.checked_out_by_user gives me error: 'File' object has no attribute 'checked_out_by_user' . What is the reason that I don't see the CheckedOutByUser property?

AniPetr avatar Mar 04 '22 13:03 AniPetr

I was checking against the current master: checked_out_by_user But it seems that this was renamed compared to previous versions: locked_by_user

All the calls should be modeled against the MS api: https://docs.microsoft.com/en-us/dotnet/api/microsoft.sharepoint.client.file.checkedoutbyuser?view=sharepoint-csom

Can you provide the package version that you are using? Maybe there is a mismatch in versions between the sharepoint instance and Office365-REST-Python-Client?

Some other possibilities / troubleshooting steps that I can think off:

  • has the account, that being used, limited permissions on the sharepoint site? Could you try with a different (privileged) user?
  • is the file that you showed "checked out"? Could you try different files, some checked out by the same user as you are testing vs a different user vs not checked out at all.

VdWWouter avatar Mar 08 '22 08:03 VdWWouter

Hi,

the following example demonstrates how to determine whether a file checked in or not:

ctx = ClientContext(site_url).with_credentials(credentials)
file = ctx.web.get_file_by_server_relative_url(file_url).get().execute_query()

if file.properties.get('CheckOutType') == 0:
    print("The file is checked out for editing on the server")
elif file.properties.get('CheckOutType') == 1:
    print("The file is checked out for editing on the local computer.")
else:
    print("The file is not checked out.")

vgrem avatar Nov 21 '22 15:11 vgrem

Thank you very much for this solution :)

AniPetr avatar Nov 23 '22 13:11 AniPetr