Closed addin-dev-24 closed 2 months ago
Hi, for clarity, a Root Web is the highest level Web of a Site Collection, not the Root of your SharePoint tenant.
You're going to want to use the Web Factory method as outlined by our docs here. https://pnp.github.io/pnpjs/sp/webs/
const root = Web("https://tenant.sharepoint.com").using(SPFx(this.context));
@bcameron1231 Thank you for the information. It was very helpful. As you mentioned, I was under the impression that rootWeb() returns data about the root of the SharePoint tenant. I did some research and found the code below to get the root of the tenant:
import "@pnp/sp/sites";
import { SPFI, SPFx, spfi } from '@pnp/sp';
private _rootSp: SPFI;
const currentSiteUrl = this.context.pageContext.web.absoluteUrl;
const tenantRootUrl = new URL(currentSiteUrl).origin;
this._rootSp = spfi(tenantRootUrl).using(SPFx(this.context));
const rootWeb = await this._rootSp.site.getRootWeb();
const currentSiteUrl = this.context.pageContext.web.absoluteUrl; const tenantRootUrl = new URL(currentSiteUrl).origin;
These code lines will get the current web site URL and construct the tenanu URL by using the Origin
of current URL. This code will not work if tenant root and current web site have different domains(custom domain)
This issue is locked for inactivity or age. If you have a related issue please open a new issue and reference this one. Closed issues are not tracked.
What version of PnPjs library you are using
3.x
Minor Version Number
20
Target environment
SharePoint Framework
Additional environment details
I am using a SharePoint web part extention.
Question/Request
I am developing a SharePoint web part extension. I am trying to get a List from my root web site. I use the following code,
Both rootWeb and rootwebData return details about current web site. Not the details about root web site. What cloud be the issue here