Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Working With: Webs

Patrick Rodgers edited this page Jan 23, 2017 · 7 revisions

Working With: Webs

Webs are one of the fundamental entry points when working with SharePoint. Webs serve as a container for lists, features, sub-webs, and all of the entity types.

Get A Web's properties

import pnp from "sp-pnp-js";

// basic get of the webs properties
pnp.sp.web.get().then(w => {

    console.log(w.Title);
});

// use odata operators to get specific fields
pnp.sp.web.select("Title").get().then(w => {

    console.log(w.Title);
});

// use with a simple getAs to give the result a type
pnp.sp.web.select("Title").getAs<{ Title: string }>().then(w => {

    console.log(w.Title);
});

Get Complex Properties

Some properties, such as AllProperties, are not returned by default. You can still access them using the expand operator.

import pnp from "sp-pnp-js";

pnp.sp.web.select("AllProperties").expand("AllProperties").get().then(w => {

    console.log(w.AllProperties);
});

Get a Web Directly

You can also use the Web object directly to get any web, though of course the current user must have the necessary permissions. This is done by importing the web object.

import { Web } from "sp-pnp-js";

let web = new Web("https://my-tenant.sharepoint.com/sites/mysite");

web.get().then(w => {

    console.log(w);
});
Clone this wiki locally