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 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,

Content editor web part missing in SharePoint/Modern SharePoint.

Media and content editor web part missing in SharePoint online. At Some Point, you need to add content editor web part into the modern site but the content editor web part did not appear on the page, to appear content editor web part on page you need to follow the below steps. 1 Log in as the SharePoint Global Administrator or SharePoint Administrator. 2.  Log in and navigate to your site collection ("") and under the site settings activate the below features.   Site settings – site features – SharePoint Server Publishing .   Site Settings – Site Actions – Manage site features- SharePoint Server Publishing Infrastructure.                For this, you also need to enable Custom site scripts on your site collection(But In Modern SharePoint Its not recommended to enabling custom site scripting)  For this go to the  SharePoint Admin center – Settings -  Classic settings page (option mentioned on page)- Scroll the page you found an optio

Save site as template option in sharepoint online

In this article, we are going to learn about "save site as template option missing in sharepoint". When  you want  to replicate a site that you have already created and for this, you have to save site as template.  For this,  you go  on  Site setting   and then   move to  Site  action   but you did not  find  the option “ Save site as template ” option.    There are several reasons behind the missing of "save site as template" option, to get this option check options below mention.   Custom script is not allowed  on tenant   On the new office 365 tenants or we say in Modern SharePoint experience by default the custom scripting is not allowed  on the tenant. If custom script is not allowed on your tenant some features will not work  o n your tenants. In common terms you may not able to  save site as template , options to create web part page will not appear on, some web parts  ( like media and content editor) will also not there.   How to