How to: Create a Custom Document Library

Posted Wednesday, June 11, 2008 8:53 AM by CoreyRoth

Not too long ago, I talked about how to remove the Explorer View from a document library.  As part of the post, I mentioned that I would post how to build a custom document library in the near future.  That is what I am covering today.  I really don't know what the best practice is on how to create a document library, I am just going to show you how I have done it in the past.

Usually, the way I start is by taking a copy of the existing builtin SharePoint DocumentLibrary feature and add it to a new Visual Studio solution.  Typically I would put this in a 12 hive folder (i.e. TEMPLATE\FEATURES).  The next step is I rename the DocumentLibrary feature folder (i.e. CustomDocumentLibrary).  The next thing you will want to do is edit the Feature.xml file.  We have to make some basic changes so that this is considered a new feature.  Therefore, you will want to pick a new GUID for the Id and give it a new Title and Description.  You may also want to change Hidden to False so that you can activate it and deactivate it through the UI.

Next, we need to edit the ListTemplates/DocumentLibrary.xml file.  This file defines the list template itself.  The first thing you need to change is the Type.  The Type number for a Document Library is 101.  It is recommended that user defined list templates start with 10000, so pick any number in that range that isn't used.

The next file you need to modify is the DocLib/Schema.xml file.  On the root List element, you will want to change at the minimum the Title element.  You may also want to set EnableContentTypes to true if you want to use custom content types.  Set FolderCreation to false if you have a custom folder type and set VersioningEnabled to true if you want versioning enabled in the document library.  The Url property I believe is the default URL that you document library will use when created.  It is specified as a relative path (usually just the folder name).   Here is what a typical root list element looks like.

<List xmlns:ows="Microsoft SharePoint" Title="My Custom Document Library" Direction="$Resources:Direction;" Url="My Custom Documents" BaseType="1" xmlns="http://schemas.microsoft.com/sharepoint/" EnableContentTypes="True"  FolderCreation="false" VersioningEnabled="true">

 

I have been leaving the BaseType attribute set to 1 and things have been working fine.  However, I have a feeling that it should probably be set to 101 so that Document Library is the base type.  In the MetaData section, you can override the folder and document content types.  I discussed how to properly do that in this post.  You just need to reference the content types you are using and then also add Field elements for each custom site column you are using in those content types.  Again, the post mentioned above describes how to do that.   The Scema.xml file is also where you can remove (or create) different views for your document library.  This is where you would go to remove the explorer view that I mentioned a while back.

Once you have made these changes, you are ready for deployment.  There are other files in the DocLib folder, but I typically don't mess with them.  Your custom document library can be deployed by copying out the feature and using stsadm or you can create a solution file for it.  Once the feature is activated you are ready to create instances of your new document library.  Also note that the Visual Studio Extensions for SharePoint can also create a lot of these files for you, but you will still need to go through and customize your various XML files.

Comments

# Links (6/12/2008) &laquo; Steve Pietrek - Everything SharePoint

Pingback from  Links (6/12/2008) &laquo; Steve Pietrek - Everything SharePoint

# re: How to: Create a Custom Document Library

Thursday, November 26, 2009 4:06 AM by Vishal

Hi Steve,

I have done the same thing and facing some problem at the time of coping the document library created from this feature.

When I save the Doc lib using SaveAsTemplate() it save it properly in List Templates however when I use GetCustomListTemplates() it does not returns the the above saved template.

Can you please let me know that it there any property which i need to set.

Thanks !

# re: How to: Create a Custom Document Library

Wednesday, June 1, 2011 5:52 AM by John Bates

Once deployed, how do I add the new custom document library?

# re: How to: Create a Custom Document Library

Wednesday, June 1, 2011 8:16 AM by CoreyRoth

@John Once you have your solution deployed, you then need to activate the feature on your site (if you haven't already).  You can then add that new document library just like you would add a builtin document library.

# re: How to: Create a Custom Document Library

Tuesday, July 16, 2013 9:41 AM by Tony

I have problems to get this step done: "add a copy of the existing builtin SharePoint DocumentLibrary feature to a new Visual Studio solution". Can you please explain how to do that? Thanks in advance.

# re: How to: Create a Custom Document Library

Tuesday, July 16, 2013 10:35 AM by CoreyRoth

@tony so these instructions are quire dated (SharePoint 2007).  Basically, you copied the document library feature directly from the 12 hive (at the time) and then renamed it and customized it.  

Now with Visual Studio 2012, it is much easier.  Just use the new document library SharePoint Project Item and it will walk you through the steps.

# HowtoAddChildItemCountstoaSharePointDocumentLibrary | Jeremy Thake Dev Blog

Pingback from  HowtoAddChildItemCountstoaSharePointDocumentLibrary | Jeremy Thake Dev Blog

# How to: Add Child Item Counts to a SharePoint Document Library | SharePointDevWiki.com

Pingback from  How to: Add Child Item Counts to a SharePoint Document Library | SharePointDevWiki.com

Leave a Comment

(required)
(required)
(optional)
(required)