SharePoint Document Library Sync to OneDrive
When a new file is added to a SharePoint document library, automatically copies it to a mirrored folder structure in OneDrive for offline access. Useful for field workers who need offline file access.
Provided as-is, without warranty of any kind. Review and test each pattern in a non-production environment before deploying it to live automations. See our Terms.
Overview
FlowLibs - SharePoint Document Library Sync to OneDrive is a Beginner-tier reference flow that mirrors files added to a configurable SharePoint document library into a OneDrive for Business folder. It uses a webhook-style SharePoint trigger (GetOnNewFileItems, OpenApiConnectionNotification) for instant per-file fan-out — no polling overhead — and applies a configurable size cap so very large files do not throttle OneDrive.
The flow ships in Off state. Activation requires only (1) authorizing the SharePoint Online and OneDrive for Business connections and (2) overriding the four environment variables to point at the source library and destination folder for the target tenant.
Use Case
Field workers, mobile users, and travelling staff often need access to documents that live in a curated SharePoint document library while disconnected from the corporate network. OneDrive for Business syncs to the local file system on Windows, macOS, iOS, and Android, so mirroring SharePoint content into a personal OneDrive folder gives those users an offline copy without granting them direct SharePoint access from outside the tenant.
The flow is ideal for teams that:
- Sales reps need price sheets, product spec PDFs, and proposal templates available offline before customer visits.
- Field service technicians need installation manuals and safety datasheets cached on tablets.
- Contractors with limited SharePoint access need read-only copies of the latest project documents.
- Executives want a OneDrive-cached copy of a quarterly board pack for offline travel reading.
Flow Architecture
When_a_File_Is_Added_to_Source_Library
SharePoint GetOnNewFileItems (OpenApiConnectionNotification)Subscribes to the source library and fans out one flow run per new file.
Init_varSharePointSiteUrl
InitializeVariable (string)Binds flowlibs_SharePointSiteURL to a working variable.
Init_varSourceLibraryId
InitializeVariable (string)Binds flowlibs_DocLibSyncSourceLibraryId to a working variable.
Init_varOneDriveFolder
InitializeVariable (string)Binds flowlibs_DocLibSyncOneDriveFolder to a working variable.
Init_varMaxFileSizeBytes
InitializeVariable (integer)Computes the size cap in bytes from the MB env var: mul(int(parameters('Max File Size MB (flowlibs_DocLibSyncMaxFileSizeMB)')), 1048576).
Init_varSyncTimestamp
InitializeVariable (string)Captures utcNow() once for both the success and skipped summaries.
Get_File_Content_From_SharePoint
SharePoint GetFileContentStreams the file binary from SharePoint using the trigger's file Identifier. inferContentType: true lets the connector preserve the original MIME type.
Check_If_File_Within_Size_Limit
If conditionCompares the trigger's reported file length against the byte cap.
- Compose_OneDrive_Destination_Path — Builds the full OneDrive destination path: concat(varOneDriveFolder, '/', triggerOutputs()?['body/{FilenameWithExtension}']).
Environment Variables
| Schema name | Type | Default | Description |
|---|---|---|---|
| flowlibs_SharePointSiteURL | String | https://your-tenant.sharepoint.com | Root SharePoint site hosting the source library. |
| flowlibs_DocLibSyncSourceLibraryId | String | <configure> | GUID of the document library to monitor. Override with the target tenant's library ID (e.g. find via https://{site}/_api/web/lists/getbytitle('Documents')?$select=Id). |
| flowlibs_DocLibSyncOneDriveFolder | String | /FlowLibs Document Library Sync | OneDrive folder path where files are mirrored. Subfolders are auto-created on first write. Leading slash required. |
| flowlibs_DocLibSyncMaxFileSizeMB | String | 100 | Files larger than this are skipped to avoid OneDrive throttling. Stored as a String to comply with the FlowLibs env var rule and cast to integer at runtime via int(...). |
Connectors & Connections
| Connector | API name | Actions used |
|---|---|---|
| SharePoint Online | shared_sharepointonline | GetOnNewFileItems (trigger) GetFileContent |
| OneDrive for Business | shared_onedriveforbusiness | CreateFile |
Note — All connections are referenced as solution connection references; the flow is portable between environments as long as a connection is mapped at import time.
Customization Guide
Almost every realistic variant of this flow can be implemented by changing environment variable values. A few cases require small edits inside the flow definition — those are called out explicitly below.
- Point the flow at your tenant via the four environment variables
- Set flowlibs_SharePointSiteURL to the root URL of the site that hosts the source library (e.g., https://contoso.sharepoint.com/sites/Operations). Set flowlibs_DocLibSyncSourceLibraryId to the GUID of the library you want to monitor (find via /_api/web/lists/getbytitle('Documents')?$select=Id or via Library settings → URL parameter List=). Set flowlibs_DocLibSyncOneDriveFolder to the destination folder path (e.g., /Field Service Docs) — leading slash required, folder is auto-created on first sync. Set flowlibs_DocLibSyncMaxFileSizeMB to your preferred cap (default 100 MB; raise to 250 for video/CAD-heavy libraries, lower to 25 for bandwidth-constrained scenarios). After updating env vars, re-authenticate the SharePoint and OneDrive connection references and turn the flow On.
- Filter out temp / lockfile extensions
- Add a Filter Array (or Condition) action between the trigger and Get_File_Content_From_SharePoint to skip files of certain extensions (e.g., .tmp, .~$*) so you do not sync editor lock files or Office temp artifacts.
- Notify the destination user on new sync
- Append a Notifications SendNotification call inside the True branch to push a mobile alert to the destination user when a new file lands in their OneDrive folder.
- Overwrite semantics on filename collision
- Replace the OneDrive CreateFile with UpdateFile if you want overwrite semantics on filename collision instead of letting OneDrive auto-rename to ' (1).ext'.
- Capture failures into a SharePoint error log
- Wrap the True branch in a Scope with a parallel Configure-Run-After Compose to capture failures (timeouts, OneDrive throttles, permission errors) into a SharePoint error log list for triage.
Key Expressions
The flow is intentionally light on Power Fx / WDL gymnastics — the heaviest expressions are the branch-name concatenation and the approval outcome check. They are listed below in the order they appear in the flow.
EXPR.01Compute byte-level size cap from MB env var
Used in Init_varMaxFileSizeBytes — multiplies the user-friendly MB value by 1,048,576 to get bytes for comparison against SharePoint's body/{Length}.
EXPR.02Compose OneDrive destination path
Used in Compose_OneDrive_Destination_Path — joins the configured destination folder with the original SharePoint filename so OneDrive mirrors the file under the same name.
EXPR.03Size-limit comparison
Used in Check_If_File_Within_Size_Limit. The coalesce(..., '0') guard is intentional: if the SharePoint trigger ever omits body/{Length} for a malformed item, the cast int('0') returns 0 and the file passes the size check rather than failing the run with a null-conversion error.
EXPR.04Trigger file ID for GetFileContent
Used as the id parameter of Get_File_Content_From_SharePoint to stream the new file's binary.
EXPR.05File name for OneDrive CreateFile
Used as the name parameter of Create_File_in_OneDrive — preserves the original SharePoint filename in the OneDrive copy.
Comments
Sign in to join the conversation.
Sign inNo comments yet. Be the first to share your experience with this flow.