Skip to content

Moving files between Sharepoint folders cause issues only sometimes #209

Open
@surajram1

Description

@surajram1

As I attempt to move files from one folder to a sub-folder - similar to this example below, I find that this works for certain excel files but not for some others in the same folder. I can't seem to find any pattern in file names or size for this.

ctx = ClientContext(site_url, ctx_auth)
# get a source file located in library 'Shared Documents'
source_file = ctx.web.get_file_by_server_relative_url("/teams/Team123/Shared Documents/Guide.docx")
# move a file into sub folder called 'Archive'
source_file.moveto("/teams/Team123/Shared Documents/Archive/Guide.docx", 1)
# execute a query
ctx.execute_query()

The error I receive is ClientRequestException: (None, None, "401 Client Error: Unauthorized for url:..... which is weird as I authenticated through client ID and Secret and all the files are in the same folder but only some files have this issue.

I find when I was using Sharepy, these files are moved without issue when I call the files by 'GetFileById' whereas in office365 library, I am taking file by relative url (get_file_by_server_relative_url). I didn't find a way to take file by ID here. Can someone help with this

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions