A Complete Guide to Copy Document Library to Another SharePoint Site

copy document library from one site to another
Stephen King ~ Modified: February 29th, 2024 ~ Migration ~ 7 Minutes Reading

SharePoint is playing an immense role in improving the collaboration in the organizations. It is used to create distinct types of sites and subsites such as communication sites, developer sites, and many more. It makes use of a Document library and lists to store the data. It is easy to move SharePoint list to another site. But when there is a scarceness to copy document library to another SharePoint site because of distinguishing reasons then users fail to do so.

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. So now let’s find the ways in this post to migrate SharePoint library to another site.

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. Modern SharePoint Site

Follow the below steps to copy document library to another in SharePoint site.

  • 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 Site

There is one more method to move document library from one site to another in SharePoint online. 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 copy document library from one site to another. 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. Copy Document Library from One Site to Another 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 copy 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 migrate SharePoint library to another site using an automated tool.

Download Now Purchase Now

Step 1. Download and Run the tool on the system. Select Source and Destination as Office 365.

source and destination
Step 2. Select the checkbox of Sites and use the Date filter.

workload
Step 3. Complete the required credentials for the Source Office 365 account. Validate all the credentials and then Next.

source details
Step 4. In the destination window, enter the details of the destination Office 365 account then validate and hit Next.

destination details
Step 5. Fetch the users into the tool from the Fetch Users, Import Users, and Download template options.

load users
Step 6. Load the sites to the automated tool by the given options: Fetch Sites, Import Sites, and Download template.

load sites
Step 7. Finally, hit the Start Migration button to copy document library from one site to another.

start migration

Conclusion

Because of the nonexistence of an 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.