We need to move documents from sub site libraries to the main site main document library. We'd like to retain version history.
What is the best way to do this?
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.
Sign up to join this communityThere are couple of methods you can try which retain the versions history when moveing the files from one library to other.
Read more the above methods here: Move Document Library in SharePoint with metadata
All of the above methods have its own pros and cons but you can try 2nd or 3rd with less efforts.
We can do it by many ways :
Using the list template approach
Save the sub site list template with content, then create the list using that template in the main site.
Using the third-party migration tool
You can use any of the third-party migration tools like ShareGate, Metalogix etc.
Using the PowerShell script
Using the PowerShell script also we can move the document from sub site document library to root site library.
Using the workflow and send to data connection also we can move the document.
1.Save the library as a template.
SharePoint Online: Save List as Template Missing?
2.Use ShareGate: https://sharegate.com/
3.Use PnP PowerShell to copy all files and folders between document libraries with metadata.
#Function to copy all Items from one library to another
Function Copy-AllDocuments($SourceLibraryName, $TargetLibraryName)
{
#Get Source and Target Libraries
$SourceLibrary = Get-PnPList -Identity $SourceLibraryName -Includes RootFolder
$TargetLibrary = Get-PnPList -Identity $TargetLibraryName -Includes RootFolder
#Copy All Files and Folders from Source to Target Library
Copy-PnPFile -SourceUrl $SourceLibrary.RootFolder.ServerRelativeUrl -TargetUrl
$TargetLibrary.RootFolder.ServerRelativeUrl -OverwriteIfAlreadyExists -Force -
SkipSourceFolderName
#Get All Items from Source Library
$SourceItems = Get-PnPListItem -List $SourceLibraryName
$TargetItems = Get-PnPListItem -List $TargetLibraryName
#Get All Items in the Source Library
ForEach($SourceItem in $SourceItems)
{
#Get Metadata from Source Items
$Metadata = @{
'Title' = $SourceItem.FieldValues.Title
'Created'= $SourceItem.FieldValues.Created.DateTime
'Modified' = $SourceItem.FieldValues.Modified.DateTime
'Author' = $SourceItem.FieldValues.Author.Email
'Editor' = $SourceItem.FieldValues.Editor.Email
}
#Update Metadata in Target Items
ForEach($TargetItem in $TargetItems)
{
If($SourceItem.FieldValues.FileLeafRef -eq
$TargetItem.FieldValues.FileLeafRef)
{
Set-PnPListItem -List $TargetLibrary -Identity $TargetItem.Id -Values
$Metadata | Out-Null
}
}
}
}
#Connect to PnP Online
$SiteURL = "your site collection URL"
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
#Call the function to copy all files between document libraries
Copy-AllDocuments "document library A name" "document library B name"
You still Map a network drive to a SharePoint library. Then copy/cut and past
In the pane on the left, right-click the Network folder and select Map network drive.
Click the link named Connect to a web site that you can use to store your documents and pictures.
Click Next twice to walk through the informational steps of the Add Network Location wizard.
Under the Specify the location of your site heading, in Internet or network address box, paste the address for your SharePoint site, then select Next.
Enter a descriptive name for your network location. (This name will appear as an entry in the left pane of File Explorer, under This PC or My Computer, next to a folder icon.)
Select Next, then select Finish.
In File Explorer, the mapped library appears as a folder item under This PC: