Reputation:
So I'm able to upload a file in SharePoint using office365 package, however in SharePoint it is not checked in and I had to manually do it. Is there any way function in that package to do check in?
here's my code:
def csv_to_sp(spfile_path,output):
ctx = Extract.connect()
target_folder = ctx.web.get_folder_by_server_relative_url(spfile_path)
with open(output,'rb') as content_file:
file_content = content_file.read()
target_folder.upload_file(output,file_content).execute_query()
response = 'Uploaded to sharepoint!'
return response
Upvotes: 0
Views: 377
Reputation: 514
I just got this to work for me. You need to do a second call to the object you just uploaded and call the checkin
method on it. See the three lines I added to your function. You will need to extract or supply the file name.
def csv_to_sp(spfile_path,output):
ctx = Extract.connect()
target_folder = ctx.web.get_folder_by_server_relative_url(spfile_path)
with open(output,'rb') as content_file:
file_content = content_file.read()
target_folder.upload_file(output,file_content).execute_query()
response = 'Uploaded to sharepoint!'
object_path = ctx.web.get_file_by_server_relative_url(spfile_path + <YOUR_FILE_NAME>)
ctx.load(object_path).execute_query()
object_path.checkin(comment="upload", checkin_type=2).execute_query()
return response
There are three checkin_types
for minor, major, and overwrite.
https://learn.microsoft.com/en-us/previous-versions/office/sharepoint-csom/ee542953(v=office.15)
Upvotes: 0
Reputation: 728
It sounds like the target library has one of the following going on which would cause the uploaded document to be checked out after upload:
Since you did not reference having to specify values for fields, I suspect you probably have #1 going on in your library. Try turning off the "Require Check Out" setting and retest.
Upvotes: 0