Home » Blog » Office 365 » Top 4 Unique Ways to Copy Document Library to Another SharePoint Site

Top 4 Unique Ways to Copy Document Library to Another SharePoint Site

author
Published By Raj
Debasish Pramanik
Approved By Debasish Pramanik
Published On February 28th, 2024
Reading Time 7 Minutes Reading
Category Office 365

Office 365 offers different collaborative applications. One of them is SharePoint which is one of the widely used applications used to improve the collaboration of organizations. One can create different types of SharePoint sites such as Communication and many more. The main components that help to manage the sites are lists and document libraries. But how to copy document library to another SharePoint site when an organization re-constructs itself or merges with another? If you are also someone who wants to know the solution to this query then stick to the write-up and know the different ways to migrate SharePoint library to another site.

Distinct Methods to Move Document Library from One Site to Another SharePoint Online

The document library in SharePoint stores heterogeneous data. The data inside the document library is crucial to organizations. So migrating the document library to the destination site should be carried out. Therefore through this write-up, you will find the different ways to migrate SharePoint document library to another site. So that you can select the necessary one. Let’s discuss them in detail.

Method 1. Manually Copy Document Library to Another SharePoint Site

In modern SharePoint, you can transfer document library to a different site using the below steps:-

  • Step 1. Sign to Office 365 and move to SharePoint.
  • Step 2. Choose the files or folders that you want to move or copy.
  • Step 3. Using the more options, select Copy to option.
  • Step 4. Finalize the destination on another site and select Copy here.

Note: – In the case of Move to, the history is also copied to the destination. In copy, the latest version of the document is copied.

This method is known for its simplicity in copying a document library to another site. However, it is not advised to use it for migrating large-sized document libraries to another site.

Method 2. Duplicate Document Library to Another Site

You can move document library from one site to another SharePoint online by creating a new library in the destination account. After creating the new library, duplicate the source data into the destination document library.

  • Step 1. Open the SharePoint where you want to copy the document library.
  • Step 2. From the homepage of the SharePoint site. Hit on the New > Document library.
  • Step 3. Now pick the option of “From Existing Library”.
  • Step 4. Select the source site and then the document library you want to copy.
  • Step 5. Now assign a name to the copied document library and hit Create.

This method requires several steps to complete the process. The process also becomes lengthy by creating a new document library and then adding the data to it.

Method 3. PowerShell Script to Copy Data from One Site to Another Site

You can also use the PowerShell scripts to copy document library to another SharePoint site. Let’s follow the below PowerShell scripts.

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
$SourceTemplateLists = $SourceCtx.Site.GetCustomListTemplates($SourceRootWeb)
$SourceCtx.Load($SourceRootWeb)
$SourceCtx.Load($SourceTemplateLists)
$SourceCtx.ExecuteQuery()
$SourceTemplateList = $SourceTemplateLists | Where {$_.Name -eq $SrcLib.id.Guid}
$SourceTemplateListURL = $SourceRootWeb.ServerRelativeUrl+”/_catalogs/lt/”+$SrcLib.id.Guid+”.stp”

If($SourceTemplateList)
{
#Remove-PnPFile -ServerRelativeUrl $SourceTemplateListURL -Recycle -Force -Connection $SrcCon
$SourceTemplateList = Get-PnPFile -Url $SourceTemplateListURL -Connection $SrcCon
$SourceTemplateList.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

$SourceTemplateLists = $SourceCtx.Site.GetCustomListTemplates($SourceRootWeb)
$SourceCtx.Load($SourceTemplateLists)
$SourceCtx.ExecuteQuery()
$SourceTemplateList = $SourceTemplateLists | Where {$_.Name -eq $SrcLib.id.Guid}

$DestinationConn = Connect-PnPOnline -URL $DestinationSiteURL -Interactive -ReturnConnection
$DestinationCtx = $DestinationConn.Context
$DestinationRootWeb = $DestinationCtx.Site.RootWeb
$DestinationListTemplates = $DestinationCtx.Site.GetCustomListTemplates($DestinationRootWeb)
$DestinationCtx.Load($DestinationRootWeb)
$DestinationCtx.Load($DestinationListTemplates)
$DestinationCtx.ExecuteQuery()
$DestinationListTemplate = $DestinationListTemplates | Where {$_.Name -eq $SrcLib.id.Guid}
$DestinationListTemplateURL = $DestinationRootWeb.ServerRelativeUrl+”/_catalogs/lt/”+$SrcLib.id.Guid+”.stp”

If($DestinationListTemplate)
{

$DestinationListTemplate = Get-PnPFile -Url $DestinationListTemplateURL -Connection $DestinationConn
$DestinationListTemplate.DeleteObject()
$DestinationCtx.ExecuteQuery()
}

Write-host “Copying List Template from Source to Destination Site…” -f Yellow -NoNewline
Copy-PnPFile -SourceUrl $SourceTemplateListURL -TargetUrl ($DestinationRootWeb.ServerRelativeUrl+”/_catalogs/lt”) -Force -OverwriteIfAlreadyExists -Connection $SrcCon
Write-host “Done!” -f Green

$DestinationListTemplates = $DestinationCtx.Site.GetCustomListTemplates($DestinationRootWeb)
$DestinationCtx.Load($DestinationListTemplates)
$DestinationCtx.ExecuteQuery()
$DestinationListTemplate = $DestinationListTemplates | Where {$_.Name -eq $SrcLib.id.Guid}

Write-host “Creating New Library in the Destination Site…” -f Yellow -NoNewline
If(!(Get-PnPList -Identity $DestLibName -Connection $DestinationConn))
{

$ListCreation = New-Object Microsoft.SharePoint.Client.ListCreationInformation
$ListCreation.Title = $DestLibName
$ListCreation.ListTemplate = $DestinationListTemplate
$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 $DestinationConn

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
}
}

$SourceTemplateList = Get-PnPFile -Url $SourceTemplateListURL -Connection $SrcCon
$DestinationListTemplate = Get-PnPFile -Url $DestinationListTemplateURL -Connection $DestinationConn
$SourceTemplateList.DeleteObject()
$DestinationListTemplate.DeleteObject()
$SourceCtx.ExecuteQuery()
$DestinationCtx.ExecuteQuery()
#Remove-PnPFile -ServerRelativeUrl $SourceTemplateListURL -Recycle -Force -Connection $SrcCon
-Connection $DestinationConn
}
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

PowerShell scripts are difficult to run and a single syntax error can also create issues to migrate SharePoint document library.

Method 4. Copy Document Library to Another SharePoint Site

Now it’s time to discuss one of the efficient tools to migrate SharePoint library to another site. The experts recommend the SharePoint Online Migration Tool to move the document library. This tool is full-fledged with the latest advanced features that make the process simpler. It maintains the data security and folder hierarchy during the process. You can also move SharePoint site to another site using this tool.

There is no need to be a techy person to operate this tool. It is designed with a simple user interface so that even non-tech users can also operate this tool. It is advised to follow the SharePoint Migration checklist before start the process. Let’s follow the below steps to copy document library to another SharePoint site using the automated tool.

Download Now Purchase Now

Step 1. Download and Launch the tool. Choose Office 365 on both Source and Destination platforms.

Source and Destination
Step 2. Tick the checkbox of the Sites and apply the Date filter as per the need.

workload
Step 3. Provide the Source Office 365 credentials and validate them then move to Next.

source details
Step 4. Complete the destination Office 365 details, validate them, and then hit Next.

destination details
Step 5. Fetch the users into the tool. Choose one option from the distinct options to load the users such as Fetch users, Import users, and Download template.

load users
Step 6. Fetch the sites using the Fetch sites, Import sites, and Download template options.

fetch sites
Step 7. In the last, click on the Start Migration button to move document library from one site to another SharePoint online.

start migration to copy document library to another sharepoint site

Conclusion

Because of moving the document library to another site is a complex and confusing task. Therefore through this write-up, we have explained the distinct solutions to copy document library to another SharePoint site. All the above-explained methods can complete the process. However, because of the limitations of the other methods and understanding the cruciality of the data, the experts recommended automated tool is the right choice to successfully migrate SharePoint document library to another site.

  author

By Raj

A technical analyst and a writer with innovative ideas when it comes to technology. Provides solutions, tips and tricks to get things done using technology.