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 = '<driveID>/items/root/' + 
        $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

Adnan, a distinguished professional, boasts an impressive track record as a Microsoft MVP, having achieved this prestigious recognition for the eighth consecutive year since 2015. With an extensive career spanning over 18 years, Adnan has honed his expertise in various domains, notably excelling in SharePoint, Microsoft 365, Microsoft Teams, the .Net Platform, and Microsoft BI. Presently, he holds the esteemed position of Senior Microsoft Consultant at Olive + Goose. Notably, Adnan served as the MCT Regional Lead for the Pakistan Chapter from 2012 to 2017, showcasing his leadership and commitment to fostering growth within the tech community. His journey in the realm of SharePoint spans 14 years, during which he has undertaken diverse projects involving both intranet and internet solutions for both private and government sectors. His impact has transcended geographical boundaries, leaving a mark on projects in the United States and the Gulf region, often collaborating with Fortune 500 companies. Beyond his roles, Adnan is a dedicated educator, sharing his insights and knowledge as a trainer. He also passionately advocates for technology, frequently engaging with the community through speaking engagements in various forums. His multifaceted contributions exemplify his dedication to the tech field and his role in driving its evolution.

Leave a Reply