How to know whether in SharePoint a file is checked in or not?
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?
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_userproperty to return a user object. - or alternatively get it as a value via the properties dict on the file object:
file.properties['CheckedOutByUser']
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?
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.
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.")
Thank you very much for this solution :)