Skip to main content

Create document library using SPFx solution

  •  In this article, we are going to learn how to create(provision) document library programmatically. We can create a list or document libraries programmatically with the SPFx solution. 

In my previous article, I wrote about the Provisioning of list with SPFx web part solution. SPFx provides flexibility to provision SharePoint assets with the solution. In this article, we are going to provision a document library.

Create a client-side web part solution

 Follow the steps for creating a client-side web part solution, run the commands using command prompt.

  • Create a directory md test-webpart
  • Move to the directory cd test-webpart 
  • Run yo @microsoft/sharepoint command to create a client-side web part.
  • Once you run the command mentioned above, you need to put some information related to the web part solution 
  •  What is your solution name? Give the name to your solution.
  •  Which baseline packages do you want to target for your component(s)?  On which environment you want to use this in our case we select "SharePoint Online Only(latest)".
  • Where do you want to place the files?  Select  Use the current folder
  • Do you want to allow the tenant admin the choice of being able to deploy the solution to all sites immediately without running any feature deployment or adding apps in sites?  No
  • Which type of client-side component to create? There are two types of client-side components, In this case, we are creating a web part, so select the web part.
  •  What is your Web part name? Give the name to the web part
  •  What is your Web part description? Describe the web part or you can skip this.
  •  Which framework would you like to use? Choose an option, as per your selection it will create a client-side component solution.
After this your solution will create time, it will take a few minutes.
  • Now the solution is ready.
  • Use code . the command to open the solution in Visual Code.

To provision SharePoint asset, we require folder structure and XML files:

  • Create a folder named "sharepoint" at the root level.
  • Create a folder named "assets" inside the "sharepoint" folder.
  • Now create new files elements.xml and schema.xml file under the "assets" folder.

  • Now copy the code mentioned below to elements.xml file.
  <?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="">
           Description="document library"

  • Now copy the code into the schema.xml
List xmlns:ows="Microsoft SharePoint" Title="MyDocLibrary" EnableContentTypes="TRUE" FolderCreation="FALSE" Direction="$Resources:Direction;" Url="Lists/MyDocLibrary" BaseType="1" xmlns="">
     <View BaseViewID="1" Type="HTML" WebPartZoneID="Main" DisplayName="$Resources:core,objectiv_schema_mwsidcamlidC24;" DefaultView="TRUE" MobileView="TRUE" MobileDefaultView="TRUE" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/generic.png" Url="AllItems.aspx">
       <XslLink Default="TRUE">main.xsl</XslLink>
       <RowLimit Paged="TRUE">30</RowLimit>
       <Toolbar Type="Standard" />
         <FieldRef Name="LinkTitle"></FieldRef>
           <FieldRef Name="ID" />
     <Form Type="DisplayForm" Url="Forms/DispForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
     <Form Type="EditForm" Url="Forms/EditForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
     <Form Type="NewForm" Url="Forms/NewForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />

Now we need to make changes in the package-solution.json file.

  • By default the package-solution.json file looks like the image shown below:

  • Now move to the package-solution.json file under the config folder and replace the code with the below code. We are making changes into the file to include features in the package-solution.json, which is responsible for provisioning(creating) of the library or any other SharePoint asset.  
  "$schema": "",
  "solution": {
    "name": "assetdeployment-client-side-solution",
    "id": "8cd172e3-a886-4705-9458-324a3d5fa9d8",
    "version": "",
    "includeClientSideAssets": true,
    "features": [{
      "title": "assetdeployment-client-side-solution",
      "description": "assetdeployment-client-side-solution",
      "id": "a6c8b716-4613-4cc9-a39e-e2412d7d08d1",  
      "version": "",
      "assets": {
        "elementManifests": [
  "paths": {
    "zippedPackage": "solution/assetdeployment.sppkg"

  • Replace the id with the new guid. You can create new guid using any online tool.

Create the package and deploy it on sharepoint :

To create a package we need to run some npm commands, follow the steps mentioned below:
  • Run the command gulp bundle --ship 
  • Run the command gulp package-solution --ship this command create .sppkg file in the solution folder under the sharepoint folder. 

  • Now login into sharepoint tenant and redirect to your app catalog site.
  • Upload the .sppkg package on site.
  • When we upload the package on the app catalog site, it prompts a dialogue box.

  • Click on the deploy and then your package will be deployed to your Sharepoint tenant.
  • Go to site collection where you want to add this app.
  • Now move to the setting and then go on Add an app.
  • Go to apps for sharepoint and select app and click on it. The app will install in some time.
  • Once the app is installed, Refresh the page and newly create document library will show.
Thank You!!


Post a Comment

Popular posts from this blog

How to register an app in SharePoint

In this article, we are going to learn how to register an app/add-in in SharePoint online. If you have created a Sharepoint provider-hosted add-in or other SharePoint solution and to access the SharePoint site or list using the app/add-in you need to register the add-in on SharePoint and to grant permission. Register app in SharePoint 1. Login into SharePoint and Navigate to register an app page. Use the URL mentioned below:          [Sitecollection URL]/_layouts/15/appregnew.aspx 2.  Once you navigate to the Register app page, a form will open. You need to fill all the fields on the form. Client Id and Client Secret  generated when we click on the generate button available next to the fields.  Title : Name of the add-in which you want to give. App Domain : Where your domain is hosted, for the local environment you can place             "". Do not include HTTP or HTTPS in App Domain. Redirect URL :  Insert the redirect URL, for t

How to create list from template in sharepoint

In this article, we are going to learn how to create a list from list template or using(.stp) file or we can say create list from existing list. Once you save the list as a template, It appears into List template option under the web designer gallery on site setting page. Steps to create list from list template: 1 Move to the site setting section where you have saved the list template. 2. When you click on the List templates, you will redirect to the List template gallery and from the list template gallery. 3. Now click on the File in ribbon and click on the upload document. 4. Browse the location where your list template is downloaded. I am uploading the template of an address list. 5.  After browsing the template, now you can give the name what you want to give to the list template and click on save. 6. Now the list template file appears into the list template gallery. Now click on the gear  icon and click on the Add an app. 7. On clicking add an app,

Permission XML for SharePoint Add-in

In this article, we will be discussing the permission XMLs, which are used to provide permission to SharePoint add-in. You can set the App only permission, by setting "true" or "false" in  AllowAppOnlyPolicy=“true” in these permission XMLs.   If add-in granted permission to tenant scope, It includes all children in scope. Before granting access to the app, need to register an app. Follow this link for step by step guide to  How to register an app/add-in in SharePoint   Providing access to add-in at tenant level: To provide access at tenant level user must have the tenant admin level permission. To grant this permission tenant admin can use this URL Search the App Id (Client ID) and it will fetch all the information which you provide at time of registration of app.   Assign full control at tenant level : <AppPermissionRequests AllowAppOnlyPolicy="true">   <AppPermissionRequest  Scop