0

I have add below PnP JS code but it's not working correctly and throwing error "Property 'moveByPath' does not exist on type 'Folder'".

await web.getFolderByServerRelativePath(oldPath).moveByPath(`${path}/${name}`, keepBoth).then(() => {

});
1
  • which PnP js version you are using? Commented May 27, 2020 at 6:50

1 Answer 1

0

Try using moveTo() like below:

import { sp } from "@pnp/sp";
import "@pnp/sp/webs";
import "@pnp/sp/folders";

// destination is a server-relative url of a new folder
const destinationUrl = `/sites/my-site/SiteAssets/new-folder`;

await sp.web.rootFolder.folders.getByName("SiteAssets").folders.getByName("My Folder").moveTo(destinationUrl);

Source: @pnp/sp/folders - move

OR

Use moveByPath like below:

import { sp } from "@pnp/sp";
import "@pnp/sp/webs";
import "@pnp/sp/folders";

// destination is a server-relative url of a new folder
const destinationUrl = `/sites/my-site/SiteAssets/new-folder`;

await sp.web.rootFolder.folders.getByName("SiteAssets").folders.getByName("My Folder").moveByPath(destinationUrl, true);

Source: @pnp/sp/folders - move by path

Note:

  1. moveByPth is added in version 2.0.2. So, use latest version of PnP JS.

PnP JS - Change Log

10
  • Which place added source path ??
    – Mavani
    Commented May 27, 2020 at 6:41
  • Source path is --> Folder with name "My Folder" under "SiteAssets" library. Commented May 27, 2020 at 6:43
  • Use latest version of PnP JS. check my updated answer. Commented May 27, 2020 at 6:57
  • Update version for sp-pnp-js ?
    – Mavani
    Commented May 27, 2020 at 7:16
  • 1
    Yes, you can use updated version.You can update it using npm i @pnp/pnpjs or npm i @pnp/pnpjs@latest. Commented May 27, 2020 at 7:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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