in

Dot Net Mafia

Group site for developer blogs dealing with (usually) .NET, SharePoint 2013, SharePoint 2010, Office 365, SharePoint Online, and other Microsoft products, as well as some discussion of general programming related concepts.

This Blog

Syndication

Archives

Corey Roth [MVP]

A SharePoint MVP bringing you the latest time saving tips for SharePoint 2013, Office 365 / SharePoint Online and Visual Studio 2013.

How to: Create a Custom Document Library

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) « Steve Pietrek - Everything SharePoint said:

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

June 12, 2008 9:12 PM
 

Vishal said:

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 !

November 26, 2009 4:06 AM
 

John Bates said:

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

June 1, 2011 5:52 AM
 

CoreyRoth said:

@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.

June 1, 2011 8:16 AM
 

Tony said:

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.

July 16, 2013 9:41 AM
 

CoreyRoth said:

@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.

July 16, 2013 10:35 AM
 

HowtoAddChildItemCountstoaSharePointDocumentLibrary | Jeremy Thake Dev Blog said:

Pingback from  HowtoAddChildItemCountstoaSharePointDocumentLibrary | Jeremy Thake Dev Blog

August 17, 2013 3:31 PM
 

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

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

September 25, 2013 2:24 PM

Leave a Comment

(required)  
(optional)
(required)  
Add

About CoreyRoth

Corey Roth is an independent SharePoint consultant specializing in ECM, Apps, and Search.
2012 dotnetmafia.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems