Introduction
PnP-JS-Core library contains a number of extensible methods and properties. By using that we can achieve the various actions in a simple code. To know more about this library component, visit the below links,
PnP-JS-Core Library
SharePoint has a lot of building blocks in collections which are used to form a SharePoint site. Those are used to manage the contents, generate reports based on contents and settings, etc…
Syntax
pnp.sp.site.rootweb – Gets the root web of the site collection
Example
The below steps and code snippet are used to return the root web object and properties from the current site collection.
- Download Required files to use PnP-JS-Core library from the below links and upload that to Site Assets or Style Library,
- Download pnp.js PnP JS file.
- Download fetch.js Used by PnP js file to handle web requests and responses (Required in IE)
- Download promise.js Used by PnP js file to handle web requests and responses (Required in IE)
- Download pnp.js PnP JS file.
- Create new web part page and insert Content Editor web part.
- Create a sample.html file in Site Assets or Style library and insert the below code snippet.
- <!-- Required JS file -->
- <script type="text/javascript" src="/siteassets/scripts/fetch.js"></script>
- <script type="text/javascript" src="/siteassets/scripts/promise.min.js"></script>
- <script type="text/javascript" src="/siteassets/scripts/pnp.min.js"></script>
- <div id="sample"></div>
- <script type="text/javascript">
- //The below PnP property used to return the root website of the site collection
- $pnp.sp.site.rootWeb.get().then(function(web) {
- document.getElementById("sample").innerText = "Title: " + web.Title + "\r\n" + "Description: " + web.Description;
- }).catch(function(err) {
- alert(err);
- });
- </script>
- Add the URL of sample.html file to the content editor webpart.
- Click ok to apply the changes to the webpart and save the page.
- Now the page displays the title and description of the root website.
Output

Conclusion
PnP-JS-Core library has a lot of simple extension properties and methods that help increases the performance and reduce the number of lines for code.

Vipin TyagiPosted Jul 6, 2016, 5:23 AM
Thanks Shantha Kumar T Sir
kalu singh raoPosted Jul 1, 2016, 7:45 AM
Nice...
Vipin TyagiPosted Jul 1, 2016, 6:39 AM
Is there any official document to learn some basics to advance in PnP
Vipin TyagiPosted Jul 1, 2016, 6:38 AM
Thanks ,But I'm using try catch and Sir It is not working in Mozilla Developer edition but fine with chrome and IE.
Vipin TyagiPosted Jul 1, 2016, 2:47 AM
Need Your help Sir!
Vipin TyagiPosted Jul 1, 2016, 2:47 AM
Finished up and getting this error- 'headers' member of RequestInit could not be converted to any of: Headers, ByteStringSequenceSequence, ByteStringMozMap.
Vipin TyagiPosted Jul 1, 2016, 2:47 AM
What about try block?
Debasis SahaPosted Jun 30, 2016, 7:22 AM
Nice one..
Kapi ShivharePosted Jun 30, 2016, 7:16 AM
Nice
Prasham SabadraPosted Jun 30, 2016, 12:56 AM
Thanks for Sharing!
Santhakumar MunuswamyPosted Jun 30, 2016, 12:40 AM
Thank you for nice article
RajaPosted Jun 30, 2016, 12:24 AM
Nice Share...
kalu singh raoPosted Jun 29, 2016, 10:57 PM
Nice...