According to the pnp.js docs at: https://github.com/pnp/pnpjs/blob/dev/packages/sp/src/folders.ts

there is a method called moveTo() which presumably moves a folder to a destination. However, the library throws this error:

'odata.error': { code: '-1, Microsoft.SharePoint.Client.ResourceNotFoundException',...

I'm able to get() the folder from the source and I've successfully created a dumb folder in the destination path, but the moveTo() method just doesn't work and it seems it's not implemented in the SharePoint API.

Any thoughts?


code below:

    .then( (result) => {
      //do whatever
  • Can you please add the code you are using to get the folder and move to your question?? – Ganesh Sanap Oct 4 '19 at 10:31
  • Note that "sp.web.getFolderByServerRelativeUrl(${relative_url}).get() does work – Andrés Biarge Oct 4 '19 at 10:45
  • @GaneshSanap code added – Andrés Biarge Oct 4 '19 at 10:53

Looks like this is a known issue currently in the pnp.js library. Found the following pull request that has been merged back to the dev branch, as well as is a part of the 1.3.6 Milestone that still is not released yet.

The summary of the fix that was made is the following:

The function Folder.moveTo() used the .toUrl() function, which returned a relative url, so it was not possible to get the host url. Because of this, it returned a 404 error. Replaced it with the value of "odata.id" which includes the absolute url.

Based on the changes they have made, you can get this to function in the interim by the following code.

const source = `${parent_url}/${list}/${folder}`;
const destUrl = `${parent_url}/${list}/${folder}`;

sp.web.getFolderByServerRelativeUrl(source).select("ServerRelativeUrl").get().then(({ ServerRelativeUrl: srcUrl, ["odata.id"]: absoluteUrl }) => {
    const client = new SPHttpClient();
    const webBaseUrl = absoluteUrl.id.split("/_api")[0];
    const hostUrl = webBaseUrl.replace("://", "___").split("/")[0].replace("___", "://");
    const methodUrl = `${webBaseUrl}/_api/SP.MoveCopyUtil.MoveFolder()`;
    return client.post(methodUrl, {
        body: jsS({
            destUrl: destUrl.indexOf("http") === 0 ? destUrl : `${hostUrl}${destUrl}`,
            srcUrl: `${hostUrl}${srcUrl}`,
    }).then((r) => r.json());
}).then((result) => {

Update 10/14/19: The Pnp.js library has been updated to 1.3.6 and the fix should be in the new version.

| improve this answer | |
  • Allright, thanks for responding. So the answer is wait till the next release? Not sure if that's what u mean – Andrés Biarge Oct 4 '19 at 18:58
  • @AndrésBiarge Correct. They have made the change to the code but have not released it to the NPM Package. Please see edit above as I provided how you can get around it until then. – Joe W Oct 7 '19 at 21:24
  • @AndrésBiarge Updated answer again as the Pnp Library has been updated to 1.3.6 and should now function properly with your original syntax. – Joe W Oct 14 '19 at 20:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.