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(() => {
});
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(() => {
});
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:
npm i @pnp/pnpjs
or npm i @pnp/pnpjs@latest
.
Commented
May 27, 2020 at 7:52