I have a module that posts a file (or sometimes multiple files) to a SharePoint folder. After the module does some other (unrelated processing), I want to move the file(s) from one folder in SharePoint to another. I see an upload and a download, but I don’t see a move or a delete. Has anyone done this? AI says use the API call, but I can’t seem to figure that out either. Any help is appreciated.
Hi Tracy.
You can use HTTP Make a request with MS Graph API.
From Microsoft Graph API’s documentation:
To move files in SharePoint using a PATCH request, you typically need to update the properties of the file or folder you want to move. The PATCH request allows you to modify specific attributes of the resource.
Generally, moving files in SharePoint may involve updating the file’s location or parent folder, which can be done by specifying the new path in the request body of the PATCH command. You would send the PATCH request to the URL of the file you want to move, including the new location as part of the properties you are updating.
For example, if you have a file at a certain URL and you want to change its parent folder, your PATCH request would look something like this:
PATCH /sites/{site-id}/_api/web/GetFileByServerRelativeUrl('/Folder1/File.txt') { "ParentFolder": "/Folder2" }Make sure to replace the placeholders with actual values relevant to your SharePoint environment.
How would one accomplish this if you had the file(s) in ‘/Folder1/File.txt’ but wanted to move it to ‘/Folder1/Folder2/File.txt’, so one level further?