
There are multiple ways of Uploading folder structure with files to a SharePoint document library which make the life easier for the end users to access content from any location directly by accessing the SharePoint site. Today I am sharing four different ways for uploading folder structure to a SharePoint Document library, there multiple ways but I will share the details regarding drag n drop, OneDrive Sync Client, using migration tools and Graph APIs.
1 – Browser Drag and Drop
Easiest way is using the browser and just drag and drop files. This way all the folders and files will be uploaded in the same structure but if there are any large files and then upload might get stuck.
2 – Using OneDrive Sync Client
You can also use OneDrive sync client to upload content a SharePoint document library by sync the document library to your local folder and copy folder structure to the local path of document library. OneDrive Sync client will automatically upload all the files. But these two options are only applicable if you are uploading content from local machines or through network folder and this would require manual effort.
3 – Migrations Tools
There multiple migration tools available in the market which can be used to migrated content from local drives or file shares to SharePoint online. 3rd Party migration tools are much easier to use and you can apply custom metadata using them but that will add some additional costs.
In SharePoint Online, you can also user Migration manager or Mover.IO for content migration from file servers. Both are free tools available in Microsoft 365.
4 – Using Graph APIs
The 4th way which I am suggesting is programmatically, again there are multiple ways to upload files and folders programmatically but today I am going to Microsoft Graph PowerShell script for uploading folders and files to SharePoint document library. Below is a PowerShell script which can be used to upload files to SharePoint document library, you need to pass the drive id to and folder structure will be copied to that location.
function UploadFolderStructure($baseDirectory) {
$directories = get-childItem -path $baseDirectory -recurse -directory
foreach ($directory in $directories) {
$createFolderURL = 'http://graph.microsoft.com/v1.0/drives/<driveID>/items/root/' +
$_.FullName.Replace($baseDirectory,'').Replace('\','/')
$uploadFolderRequestBody = @{
name= "$file"
folder = @{}
"@microsoft.graph.conflictBehavior"= "rename"
} | ConvertTo-Json
invoke-restMethod -headers $header -method Post -body $uploadFolderRequestBody `
-contentType "application/json" -uri $createFolderURL
}
}
#Calling funcation and passing local directory path
UploadFolderStructure('C:\UploadDocuments\TestUpload')
No Comments