Moving files between sites (PowerShell & JavaScript)

%3CLINGO-SUB%20id%3D%22lingo-sub-53764%22%20slang%3D%22en-US%22%3EMoving%20files%20between%20sites%20(PowerShell%20%26amp%3B%20JavaScript)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-53764%22%20slang%3D%22en-US%22%3E%3CP%3EI%20need%20to%20move%20a%20file%20between%20two%20sites%2C%20the%20soruce%20is%20a%20sub%20site%20of%20ther%20target%20site.%20The%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-PowerShell%2Fblob%2Fmaster%2FDocumentation%2FMovePnPFile.md%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Eexample%20documentation%20for%26nbsp%3BMove-PnPFile%3C%2FA%3E%26nbsp%3B%20seem%20to%20support%20moving%20between%20site%20collections%20and%20should%20there%20for%20work%20when%20moving%20between%20sites%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EExample%3A%3C%2FP%3E%3CP%3ESource%20%3D%20%3CA%20href%3D%22http%3A%2F%2Fxyz.sharepoint.com%2Fsites%2Fsystem%2Fsubsite%2Fdocuments%2Ftest.txt%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fxyz.sharepoint.com%2Fsites%2Fsystem%2Fsubsite%2Fdocuments%2Ftest.txt%3C%2FA%3E%3C%2FP%3E%3CP%3ETarget%20%3D%26nbsp%3B%3CSPAN%3E%3CA%20href%3D%22http%3A%2F%2Fxyz.sharepoint.com%2Fsites%2Fsystem%2Fdocuments%2Ftest.txt%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fxyz.sharepoint.com%2Fsites%2Fsystem%2Fdocuments%2Ftest.txt%3C%2FA%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhen%20i%20try%20this%20i%20first%20use%20Connect-PnPOnline%20and%20uses%20to%20url%20to%20the%20siter%20were%20the%20documet%20is%20located%20(soruces%20site).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhen%20i%20use%20a%20relative%20target%20url%20i%20get%20the%20following%20errror.%3C%2FP%3E%3CP%3E%22Parameter%20name%3A%20Specified%20value%20is%20not%20supported%20for%20the%20serverRelativeUrl%20parameter.%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhen%20i%20use%20a%20absolute%20target%20url%20i%20get%3C%2FP%3E%3CP%3E%22URL%20is%20not%20for%20this%20web%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20i%20move%20the%20document%20within%20the%20same%20site%20it%20works%20flawlessly%2C%20am%20i%20missing%20something%3F%20Or%20is%20moving%20files%20between%20sites%20not%20supported.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20know%20that%20the%20server%20side%20object%20model%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Foffice%2Fms468280.aspx%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3ESPFile.MoveTo%3C%2FA%3E%26nbsp%3Bonly%20supports%20moving%20files%20withing%20the%20same%20site.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20aware%20that%20PnP-JS-Core%20also%20have%20a%20moveTo%20implementation%20but%20my%20understanding%20is%20that%20the%20.NET%20c%23%2C%20PowerShell%20and%20JavaScript%20version%20of%20PnP%20calles%20the%20same%20endpoint%20and%20i%20should%20therefor%20expect%20the%20same%20result%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20MoveTo%20does%20not%20support%20moving%20between%20sites%2C%20what%20is%20the%20recommended%20solution%20for%20doing%20this%20programmatically%2C%20we%20have%20a%20case%20were%20this%20is%20needed%20for%20both%20front-end%20and%20back-end%20stuff.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-53764%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EFiles%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Visitor

I need to move a file between two sites, the soruce is a sub site of ther target site. The example documentation for Move-PnPFile  seem to support moving between site collections and should there for work when moving between sites?

 

Example:

Source = http://xyz.sharepoint.com/sites/system/subsite/documents/test.txt

Target = http://xyz.sharepoint.com/sites/system/documents/test.txt

 

When i try this i first use Connect-PnPOnline and uses to url to the siter were the documet is located (soruces site).

 

When i use a relative target url i get the following errror.

"Parameter name: Specified value is not supported for the serverRelativeUrl parameter."

 

When i use a absolute target url i get

"URL is not for this web"

 

If i move the document within the same site it works flawlessly, am i missing something? Or is moving files between sites not supported.

 

I know that the server side object model SPFile.MoveTo only supports moving files withing the same site.

 

I am aware that PnP-JS-Core also have a moveTo implementation but my understanding is that the .NET c#, PowerShell and JavaScript version of PnP calles the same endpoint and i should therefor expect the same result?

 

If MoveTo does not support moving between sites, what is the recommended solution for doing this programmatically, we have a case were this is needed for both front-end and back-end stuff.

0 Replies