Create Document Library With Folders In SharePoint Using VS 2015

In this article, I would like to share the steps for creating a document library with folders in SharePoint, using Visual Studio 2015. In my previous article, we saw how to create document library manually in SharePoint Online Site.

What a SharePoint Document Library is –

  • A Document Library is a collection of files that you can share as documents with your team members.
  • A Document Library stores the files and you can maintain the data in various folders.
  • A SharePoint Document Library is a place on a site where you can create, collect, and update files with others.
  • You can set the permission to each Document Library for the users.
  • You can show a Document Library in web part pages as List View Web Parts.

SharePoint provides templates for us to create SharePoint list and library. Each and every list will have its own list instance and list definition. In Visual Studio SharePoint projects, we can see the list instance, and the folders can be added in the list instance.

Follow the below listed steps to create Library with folders.

Already we saw how to create the SharePoint project using Visual Studio 2015.

Step 1

Open your SharePoint project in VS 2015.

SharePoint

Step 2

Then, create a subfolder under this project to keep the list and libraries separate. Right click the project and choose Add >> New Folder.

SharePoint

Step 3

Provide the folder name as per your need.

SharePoint

Step 4

Right click on the library folder and select Add >> New item….

SharePoint

Step 5

When you click the “New Item”, you will get a pop up as shown below. Here,  select the list template and provide a name for your library.

SharePoint

Step 6

Then, press “Add” button to create a new library.

SharePoint

Step 7

After you click the “Add” button, you need to provide library name and template. I have selected picture library template. Then, click “Finish” button.

SharePoint

Finally, the library will be added in our SharePoint project.

SharePoint

Now, we need to add the folders inside the library. So, add the below code in sample library element.xml file.

  1. <Data>
  2.       <Rows>
  3.         <Row>
  4.           <Field Name=“ContentTypeId”>0x0120004F994A3C0FF76546A528DA0D4B515898</Field>
  5.           <Field Name=“FileLeafRef”>Images</Field>
  6.           <Field Name=“Title”> Images</Field>
  7.           <Field Name=“FSObjType”>1</Field>
  8.         </Row>
  9.       </Rows>
  10.     </Data>

SharePoint

Once you add the above code, deploy the solution from VS. Your new Library will be created successfully with folder, as shown in below image.

SharePoint
Summary

In this article, we have explored how to create a document library with the predefined folders in SharePoint using Visual Studio 2015.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s