Here, we are going to see how to create a new folder under SharePoint List using PnP JavaScript Component.

To know more about this JavaScript library, check the below links

JavaScript Example:

The below steps and code snippets used to create a new folder in SharePoint list using PnP JavaScript library,

  1. Download Required files to use PnP-JS-Core library from the below links and upload that to Site Asstes 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)
  2. Create new web part page and insert Content Editor web part
  3. Create a sample.html file in Site Assets or Style library and insert the below code snippet

The below example creates a new folder under root level of a SharePoint list or library


<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>
  
<span id="folderInfo"></span>

<script type="text/javascript">  
//The below example gets the root folder of the Documents library and create a subfolder name as "NewFolderName" under it.
$pnp.sp.web.lists.getByTitle("Documents")
    .rootFolder
    .folders
    .add("NewFolderName").then(function(data) {
        console.log(data);
        document.getElementById("folderInfo").innerHTML = "Folder created successfully.";
    }).catch(function(err) {
        console.log(err);
        document.getElementById("folderInfo").innerHTML = "Unable to create Folder.";
    });
</script>

Typescript Example:

Typescript is the superset of JavaScript and this PnP JS library is developed using the typescript specification. For developing the SharePoint Framework web parts and make the client side development easier, we can vote for typescript. The below is the typescript example for creating a new folder under root folder of the SharePoint List / Library.

import pnp from "sp-pnp-js";

pnp.sp.web.lists.getByTitle("Documents").rootFolder.folders.add("NewFolderName").then(data => {
    this.domElement.querySelector("#folderInfo").innerHTML = "Folder created successfully."
}).catch(err => {
    this.domElement.querySelector("#folderInfo").innerHTML = "Unable to create Folder."
});
Create a new folder in SharePoint List using PnP JavaScript Library
Tagged on:         

Leave a Reply

Your email address will not be published. Required fields are marked *

These articles are best for patients who want a general overview and who prefer short, easy-to-read materials. thinkingmatters.us/wp-admin/css/colors/alshrooq.php?kwv=278599 best price viagra 20 mg The overall effectiveness rate was 92. quiltingqueenval.com/netshelter/passions.php?uzx=279156 The location of the fibroid determines the risk for bleeding. 059. markbundockphotography.com/qtt-276999/ (for more information about the genetics of fibroids, please see articles published about these genes on the quotpublicationsquot page. pormenor.org/whf-278077/ The procedure has been performed since 1995 and over 100,000 women have been treated worldwide. 059. http://coehilladvisors.com/csh-275473/ viagra results video -h. On the other hand, if a physician's surgical skill is limited primarily to hysterectomy, these questions will reveal inexperience or poor results with myomectomy. Toaff me. faircrestheights.org/hla-276321/ http://stuccorainbowmusic.com/plm-276279/ To see one abstract at a time, click its link. museovilalba.org/uxv-278538/ Yoga.