Copy Document Library to Another SharePoint Site – Best 5 Methods
SharePoint plays a crucial role in improving collaboration within organizations. It is used to create distinct types of sites and subsites such as communication sites, developer sites, and many more. It uses document libraries and lists to store data. It is easy to move SharePoint list to another site. However, users often encounter errors and face difficulty in copying document libraries to another SharePoint site due to various reasons.
But now the feature to copy document libraries was appended to SharePoint Online recently. This has always been a coveted feature, especially when your library is configured with metadata such as views, and metadata columns.
Table of Content
So now let’s discuss a few ways to perform the same, in this post.
How to Move Document Library from One Site to Another in SharePoint Online?
There are several distinct ways to copy document library from one site to another. Here you will find the all possible methods in detail. So let’s begin the methods in a detailed manner.
Method 1. Transferring Document Library in Modern SharePoint Site
Follow the below steps:
- Step 1. Log in to your Office 365 account and then open SharePoint.
- Step 2. Finalize the documents that you want to copy.
- Step 3. Choose the Copy to option under the More options.
- Step 4. Select the destination on another site and then hit Copy here.
The above-discussed method is simple and easy to understand for the administrators. However, it is not feasible to copy document library to another SharePoint site in case of large-sized files and folders.
Method 2. Duplicate Document Library to Another SharePoint Site
There is one more method to perform this task. That is duplicate the document library to the destination SharePoint site. It involves several steps and these are:-
- Step 1. Launch the destination SharePoint site.
- Step 2. On the homepage of the SharePoint site. Click on the New > Document library.
- Step 3. Now choose the “From Existing Library” option.
- Step 4. Choose the source SharePoint site and then the document library files and folders that you want to copy.
- Step 5. Now provide a name to the copied document library and click on Create.
Duplicate document library to the destination requires lengthy steps. As it involves different options to choose then it also has chances of errors.
Method 3. Copy Document Library to Another SharePoint Site Using PowerShell Scripts
If you are good at technicalities then you can use the PowerShell scripts to do this task. But make sure to not miss any of the commands in between. Also, take care of the syntaxes of the command. If any of the commands are executed unevenly and improperly then the results will be manipulated.
Function Copy-PnPLibrary
{
param (
[parameter(Mandatory=$true, ValueFromPipeline=$true)][string]$SourceSiteURL,
[parameter(Mandatory=$true, ValueFromPipeline=$true)][string]$DestinationSiteURL,
[parameter(Mandatory=$true, ValueFromPipeline=$true)][string]$SrcLibName,
[parameter(Mandatory=$true, ValueFromPipeline=$true)][string]$DestLibName
)
Try {
$SrcCon = Connect-PnPOnline -URL $SourceSiteURL -Interactive -ReturnConnection
$SourceCtx = $SrcCon.Context
$SrcLib = Get-PnPList -Identity $SrcLibName -Includes RootFolder -Connection $SrcCon
$SourceRootWeb = $SourceCtx.Site.RootWeb
$SLTs = $SourceCtx.Site.GetCustomListTemplates($SourceRootWeb)
$SourceCtx.Load($SourceRootWeb)
$SourceCtx.Load($SLTs)
$SourceCtx.ExecuteQuery()
$SLT = $SLTs | Where {$_.Name -eq $SrcLib.id.Guid}
$SLTURL = $SourceRootWeb.ServerRelativeUrl+”/_catalogs/lt/”+$SrcLib.id.Guid+”.stp”
If($SLT)
{
#Remove-PnPFile -ServerRelativeUrl $SLTURL -Recycle -Force -Connection $SrcCon
$SLT = Get-PnPFile -Url $SLTURL -Connection $SrcCon
$SLT.DeleteObject()
$SourceCtx.ExecuteQuery()
}
Write-host “Creating List Template from Source Library…” -f Yellow -NoNewline
$SrcLib.SaveAsTemplate($SrcLib.id.Guid, $SrcLib.id.Guid, [string]::Empty, $False)
$SourceCtx.ExecuteQuery()
Write-host “Done!” -f Green
$SLTs = $SourceCtx.Site.GetCustomListTemplates($SourceRootWeb)
$SourceCtx.Load($SLTs)
$SourceCtx.ExecuteQuery()
$SLT = $SLTs | Where {$_.Name -eq $SrcLib.id.Guid}
$DestConn = Connect-PnPOnline -URL $DestinationSiteURL -Interactive -ReturnConnection
$DestinationCtx = $DestConn.Context
$DestinationRootWeb = $DestinationCtx.Site.RootWeb
$DLTs = $DestinationCtx.Site.GetCustomListTemplates($DestinationRootWeb)
$DestinationCtx.Load($DestinationRootWeb)
$DestinationCtx.Load($DLTs)
$DestinationCtx.ExecuteQuery()
$DLT = $DLTs | Where {$_.Name -eq $SrcLib.id.Guid}
$DLTURL = $DestinationRootWeb.ServerRelativeUrl+”/_catalogs/lt/”+$SrcLib.id.Guid+”.stp”
If($DLT)
{
$DLT = Get-PnPFile -Url $DLTURL -Connection $DestConn
$DLT.DeleteObject()
$DestinationCtx.ExecuteQuery()
}
Write-host “Copying Data…” -f Yellow -NoNewline
Copy-PnPFile -SourceUrl $SLTURL -TargetUrl ($DestinationRootWeb.ServerRelativeUrl+”/_catalogs/lt”) -Force -OverwriteIfAlreadyExists -Connection $SrcCon
Write-host “Done!” -f Green
$DLTs = $DestinationCtx.Site.GetCustomListTemplates($DestinationRootWeb)
$DestinationCtx.Load($DLTs)
$DestinationCtx.ExecuteQuery()
$DLT = $DLTs | Where {$_.Name -eq $SrcLib.id.Guid}
Write-host “Creating New Library in the Destination Site…” -f Yellow -NoNewline
If(!(Get-PnPList -Identity $DestLibName -Connection $DestConn))
{
$ListCreation = New-Object Microsoft.SharePoint.Client.ListCreationInformation
$ListCreation.Title = $DestLibName
$ListCreation.ListTemplate = $DLT
$DestinationList = $DestinationCtx.Web.Lists.Add($ListCreation)
$DestinationCtx.ExecuteQuery()
Write-host “Library ‘$DestLibName’ created successfully!” -f Green
}
Else
{
Write-host “Library ‘$DestLibName’ already exists!” -f Yellow
}
Write-host “Copy files…” -f Yellow
$DestLib = Get-PnPList $DestLibName -Includes RootFolder -Connection $DestConn
If($SrcLib.ItemCount -gt 0)
{
$global:counter = 0
$ListItems = Get-PnPListItem -List $SrcLibName -Connection $SrcCon -PageSize 500 -Fields ID -ScriptBlock {Param($items) $global:counter += $items.Count; Write-Progress -PercentComplete `
(($global:Counter / $SrcLib.ItemCount) * 100) -Activity “Getting Items from List” -Status “Getting Items $global:Counter of $($SrcLib.ItemCount)”}
$RootFolderItems = $ListItems | Where { ($_.FieldValues.FileRef.Substring(0,$_.FieldValues.FileRef.LastIndexOf($_.FieldValues.FileLeafRef)-1)) -eq $SrcLib.RootFolder.ServerRelativeUrl}
Write-Progress -Activity “Completed process$($SrcLib.Title)” -Completed
$RootFolderItems | ForEach-Object {
$DestinationURL = $DestLib.RootFolder.ServerRelativeUrl
Copy-PnPFile -SourceUrl $_.FieldValues.FileRef -TargetUrl $DestLib.RootFolder.ServerRelativeUrl -Force -OverwriteIfAlreadyExists -Connection $SrcCon
Write-host “`tCopied $($_.FileSystemObjectType) ‘$($_.FieldValues.FileRef)’ Successfully!” -f Green
}
}
$SLT = Get-PnPFile -Url $SLTURL -Connection $SrcCon
$DLT = Get-PnPFile -Url $DLTURL -Connection $DestConn
$SLT.DeleteObject()
$DLT.DeleteObject()
$SourceCtx.ExecuteQuery()
$DestinationCtx.ExecuteQuery()
#Remove-PnPFile -ServerRelativeUrl $SLTURL -Recycle -Force -Connection $SrcCon
-Connection $DestConn
}
Catch {
write-host -f Red “Error:” $_.Exception.Message
}
}
$SourceSiteURL = “https://crescent.sharepoint.com/sites/Retail”
$DestinationSiteURL = “https://crescent.sharepoint.com/sites/warehouse”
$SrcLibName = “Invoices”
$DestLibName = “Invoices V2”
Copy-PnPLibrary -SourceSiteURL $SourceSiteURL -DestinationSiteURL $DestinationSiteURL -SrcLibName $SrcLibName -DestLibName $DestLibName
Method 4. Transferring of Document Library with Metatags Using the “Save As” Option
SharePoint offers an inbuilt option i.e. “Save As” to execute this task. Moreover, you can also copy files with metadata tags in SharePoint. Below are the steps that can accomplish the task.
- Open the SharePoint site and then go to its Document Library.
- Select the essential files and folders that you want to move to the destination SharePoint site.
- Click on the Download or Save As option to export these locally.
- As the files are downloaded into (.zip) file. Navigate to the Destination SharePoint document library.
- Now, upload all the files and folders in the destination document library.
Method 5. Copy Document Library to Another SharePoint Site Using an Automated Tool
After analyzing the different manual methods. Now is the time to elaborate on the automated tool. One of the reliable solutions to transfer your document library to another SharePoint site is the Migrator Wizard SharePoint Online Migration Tool. It is recommended by the experts because of its impeccable features. This tool does not require technical knowledge to operate. Due to this, even non-tech users can also execute this tool flawlessly and move SharePoint site to another site.
You don’t need to worry about the files and folders hierarchy, this preserves the data hierarchy. It incorporates an interactive dashboard to keep an eye on the process. It offers a Delta migration option to migrate the newly arrived data to the destination site. Below are the steps to transfer your SharePoint library to another site using an automated tool.
Step 1. Download and Run the tool on the system. Select Source and Destination as Office 365.
Step 2. Select the checkbox of Sites and use the Date filter.
Step 3. Complete the required credentials for the Source Office 365 account. Validate all the credentials and then Next.
Step 4. In the destination window, enter the details of the destination Office 365 account then validate and hit Next.
Step 5. Fetch the users into the tool from the Fetch Users, Import Users, and Download template options.
Step 6. Load the sites to the automated tool by the given options: Fetch Sites, Import Sites, and Download template.
Step 7. Finally, hit the Start Migration button to move document library from one site to another.
Conclusion
Because of the nonexistence of a direct option to copy document library to another SharePoint site. There is a lot more frustration between the users. That’s why we brought this write-up, to describe some methods to move the document library to another site. Now you can choose the method that is the best fit for your needs, but choose the method wisely.
Frequently Asked Questions
Q1. How to export a document library from SharePoint?
A – To export the document library, go to the Site > Document library. Now choose the files and folders and hit the Download button.
Q2. Can I have multiple document libraries in one SharePoint site?
A – Yes, you can create multiple document libraries in SharePoint to manage your documents.
Q3. How to move files from one document library to another in SharePoint programmatically?
A – You can use SP.MoveCopyUtil.moveFolder() method to transfer a folder from one document library to another document library.