Copy-PnPFile : The remote server returned an error: (500) Internal Server Error. #2780
Comments
Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible. |
I can reproduce this. When doing the copy, it will request the URL to the SharePoint site where the file resides. This triggers a call in CSOM to: POST /sites/<sitename>/Shared%20Documents/<file>.json/_api/contextinfo This call fails if it's done on a .json file. All other file types seem to work fine, so it looks like an issue on the SharePoint Server side. Trying to fetch ULS logs to get a deeper insight. |
Thanks for following up. So this something that cannot be fixed easily? |
The issue happens in this exact line of the CopyFile command. As Koen pointed out, a call to figure the web folder URL fails when sending the URL of a JSON file. With a simple fix to the code I was able to make it work for JSON files. I will try to test it in a new branch and if it works for other file extensions I will be submitting a pull request. |
I had a look at the ULS logs and they weren't really helpful. Tried to find out in the source code of SharePoint Online why it failed but got stranded and ran out of time to spend on the issue. The call is only used to determine the URL of the site anyway, so we should be able to find another way to do so. I'll have a look at @kadu-jr his proposed solution, but it may not be that easy as we also need to think about different subsites and such. Have you tested your PR with all possible thinkable scenarios? |
You're right, @KoenZomers. I had forgotten this command can also copy a folder instead of a single file, among with other examples. I looked through the command examples and I believe the solution would be to check if the SourceUrl parameter ends in ".json" and treat it to generate the sourceWebUri, which may be an ugly workaround. |
I'm trying to copy files from document library to other on SharePoint Online using Copy-PnPFile. All the files are getting copied except for .json file. For JSON file throws "Copy-PnPFile : The remote server returned an error: (500) Internal Server Error."
Steps to reproduce.
open connection
#$connProjSite = Connect-PnPOnline -Url https://****dev.sharepoint.com/sites/TestSIte
Get files from the folder
[Microsoft.SharePoint.Client.Folder]$spFolder = Get-PnPFolder -Url "/sites/TestSIte/Shared Documents/Test" -Includes Files -Connection $connProjSite -ErrorAction Continue
Loop thru to copy files
$spFolder.Files | ForEach-Object {
[Microsoft.SharePoint.Client.File]$spFile = $_
Write-Verbose -Verbose -Message "Moving file $($spFile.Name) to $ ($clientSiteRelativeURL)/$ ($projectLegalFolderPath)"$spFile.ServerRelativeUrl -TargetUrl "/sites/TestSite/Shared Documents/Test2/$ ($spFile.Name)" -Connection $connProjSite -OverwriteIfAlreadyExists -Force
Copy-PnPFile -SourceUrl
}
This works fine on most documents, but gives the following error on JSON files.
Copy-PnPFile : The remote server returned an error: (500) Internal Server Error.
At C:\Development\SiteProvisioning\PowerShell\JSON Test.ps1:9 char:5
Which version of the PnP-PowerShell Cmdlets are you using?
What is the version of the Cmdlet module you are running?
3.22
How did you install the PnP-PowerShell Cmdlets?
The text was updated successfully, but these errors were encountered: