Forum Discussion
Need sample code to copy site pages from one site colleciton to another site collection using pnp.js
import { spfi } from "@pnp/sp";
import "@pnp/sp/webs";
import "@pnp/sp/files";
const sp = spfi(...);
// destination is a server-relative url of a new file
const destinationUrl = `/sites/dev2/sitePages/Home.aspx`;
await sp.web.getFileByServerRelativePath("/sites/dev/sitePages/Home.aspx").copyByPath(destinationUrl, false, true);
- narayanareddyDec 15, 2023Copper Contributor
Dear NicolasKheirallah ,
Thank you so much for your reply. I used the below code.
const destinationUrl="/sites/Communication2SiteForMyDevelopmentTesting/SitePages/testinganchortag.aspx";await this.sp.web.getFileByServerRelativePath("/sites/TestCommunication/SitePages/testinganchortag.aspx").copyByPath(destinationUrl, false, true);I get below Forbidden error message. I am the site collection admin in both the site collections -
RootSiteurl/sites/TestCommunication/_api/SP.MoveCopyUtil.CopyFileByPath(overwrite=@a1)?@a1=false 403 (Forbidden)Please share any suggestion you have for me to get rid of this error. Thank you so much for your help.
- Dec 15, 2023I'm guessing you've not set the permissions in the SPFX project and approved them
https://learn.microsoft.com/en-us/sharepoint/dev/spfx/use-aad-tutorial#configure-the-api-permissions-requests- narayanareddyDec 21, 2023Copper Contributor
Dear NicolasKheirallah
Thank you so much for your reply.
I was traveling and so did not get chance to reply you. I am sorry.
I am site collection admin in both the site collections and I get the below Access denied error when I check in the network tab while debugging the workbench web part. I think I am not using any Microsoft Graph API also for any permissions approvals. Moreover I am testing in the workbench and it is not yet preparted for a solution but just testing in the local work bench. Please advise if you have any ideas for fixing it in the local workbench web part. Thank you so much for your time and help.
"odata.error": {
"code": "-2147024891, System.UnauthorizedAccessException",
"message": {
"lang": "en-US",
"value": "Access denied."
}
}