If you need to get files off SP there are many ways to do it, for example syncing with OneDrive (for SP Online)- or, in Windows 10, you can access a SharePoint on-premises library as if it were a regular folder by typing its absolute URL into the address bar of any Explorer window:
Below is a method for sending files to SharePoint. If you are allowed to use PowerShell you can write a simple script to get specific files and upload them to corresponding locations in SharePoint, using the [PnP PowerShell library][1]
.
For this you must have an account with administrator access to the destination SharePoint site. In my case I am using SharePoint 2016 on-premises.
The relevant command is Add-PnPFile -Path ... -Folder ... -Checkout
, where Path
is the location of a local file, Folder
is the destination library in SharePoint, and Checkout
means that, if the file already exists, we will check it out, upload a new version, and check it back in.
This script is meant to upload two files (main.js and main.css) to the SiteAssets/project directory on the default Web. You could easily expand it to include more files or upload to multiple locations in different passes.
Upload-Files-To-Library.ps1
param (
[Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)]
[String]$HostName = "https://www.mysite.sharepoint.com",
[Parameter(Mandatory = $true, Position = 1, ValueFromPipeline = $true)]
[String]$DestinationPath = "SiteAssets/project",
[Parameter(Mandatory = $true, Position = 2, ValueFromPipeline = $true)]
[String]$LocalPath = "./build",
[Parameter(Mandatory = $true, Position = 3, ValueFromPipeline = $true)]
[String]$EditorId = "479"
)
# Get the local files
$LocalFiles = Get-ChildItem -Path $LocalPath -Include "*.js", "*.css" -Recurse -Exclude "service-worker.js"
# Connect to SharePoint
$Connection = Connect-PnPOnline -Url $HostName -CurrentCredentials -ReturnConnection
if ( $LocalFiles -and $Connection) {
Write-Host Uploading to $DestinationPath -ForegroundColor White
# Upload the files
ForEach ($file in $LocalFiles) {
Write-Host "Uploading $($file.Name)" -ForegroundColor Yellow
Add-PnPFile -Path $file.FullName -Folder $DestinationPath -NewFileName $FileName -Checkout -CheckInComment $file.Name -Values @{Editor = $EditorId} -Verbose
}
}
else {
Write-Host "Error getting files or connection." -ForegroundColor Red
}
# Disconnect from SharePoint
Disconnect-PnPOnline -Connection $connection -Verbose
Usage
e.g.
.\Upload-File-To-Library.ps1 -HostName 'https://mysite.sharepoint.com' -DestinationPath 'SiteAssets/project' -LocalPath './build' -EditorId '479'