This is to show some fun in Graph API. Readers are allowed to decide its fun or lack of quality after testing.
Move a folder from one SharePoint drive to another drive in same site.
The id of folder should not change.
As of this commit, the documentation of Graph API says the Patch on drive item cannot be used to move between drives.
But it is working!!!
Often times the code and documentation will not be in sync. There are chances that the check is not implemented by API by relying solely on documentation and assuming users will not misuse.
When tried in different environments, it failed when moving folder with large sized files in it. The exception was item not found. But behind the scene it really worked.
⚠️ Be cautious with undocumented features as Microsoft themselves cannot help, if we get stuck in production.
✅ Workaround is to use the equivalent CSOM SharePoint APIs via PnP SDKs.
Just add the drive id to the patch request.
PATCH /me/drive/items/{item-id}
Content-type: application/json
{
"parentReference":
{
"id":"<new-parent-folder-id>"
},
"name":"",
}
The undocumented request payload
PATCH /me/drive/items/{item-id}
Content-type: application/json
{
"parentReference":
{
"id":"<new-parent-folder-id>",
"driveId":"<destination drive id>"
},
"name":"",
}
- Prepare SharePoint site
- Azure portal
- Application
- Clone the repo
- Replace the values in the appsettings.json
- Run the console application. (Test application is yet to be done.)
- .Net version - .Net 6
- Nugets referenced
- Microsoft.Graph : v5.x (Code not compatible with v4.x)
- DotNet.Helpers
- easyconsolestd
- Microsoft.Extensions.Hosting
Click on the below image for the video.
- Supported. Refer the Program.cs file for more details
- The options are injected as dependency to the [MenuService](/src/MenuService.cs then those are invoked based on selection.