When creating custom Site Templates (features, definitions - whichever you prefer), one of the things most clients want is a document library included in the Site Template with a pre-defined folder structure. So I thought I would share my solution for creating a document library with a pre-populated folder structure as it is becoming more popular as of late.
Now there are actually 3 different methods of doing this:
- Through the ONET.XML file in your custom Site Template
- Through the manifest.xml file of your custom document library feature.
- Through the manifest.xml file of a custom document library instance feature.
In this post I am going to explain how to add it via option 3 (the instance feature) as this requires the least amount of code :) I am NOT going to explain how to create an list template instance feature (plenty of other posts out there).
Lets go:
- Open your features manifest file (features/feature/listTemplates/featureName.xml)
You should see something along the lines of:
<?xml version="1.0" encoding="utf-8" ?>
<!-- _lcid="1033" _version="12.0.3820" _dal="1" -->
<!-- _LocalBinding -->
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<ListInstance
FeatureId="00BFEA71-E717-4E80-AA17-D0C71B360101"
TemplateType="101"
Title="Documents"
Url="Docs"
Description=""
QuickLaunchUrl="Docs/Forms/AllItems.aspx"
/>
</Elements>
- Add the following code just before the </Elements> tag:
<Module Path="Folder01" Url="Docs\Folder" />
Note: The Url in the above tag begins with the url of the list instance
- Now, lets add a subfolder to the above folder:
<Module Path="Folder01" Url="Docs\Folder\Sub-Folder" />
You can carry on like this for as long as you like. Once you are finished, install your feature. When you activate the feature your document library will be created with your pre-loaded folder structure in place.
Below is an example of one of mine:
<?xml version="1.0" encoding="utf-8" ?>
<!-- _lcid="1033" _version="12.0.3820" _dal="1" -->
<!-- _LocalBinding -->
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<ListInstance
FeatureId="00BFEA71-E717-4E80-AA17-D0C71B360101"
TemplateType="101"
Title="Documents"
Url="Docs"
Description=""
QuickLaunchUrl="Docs/Forms/AllItems.aspx"
/>
<!-- required custom content type for this document library instance -->
<ContentTypeBinding ListUrl="Docs" ContentTypeId="0x010110" />
<!-- Single folder no sub-folders -->
<Module Path="Administration" Url="Docs/Administration" />
<!-- A Folder and associated sub-folders -->
<Module Path="Audits" Url="Docs/Audits" />
<Module Path="Audits" Url="Docs/Audits/Assurance" />
<Module Path="Audits" Url="Docs/Audits/Corporate" />
<Module Path="Audits" Url="Docs/Audits/Risk"/>
<Module Path="Audits" Url="Docs/Audits/Committee"/>
<Module Path="Audits" Url="Docs/Audits/Fraud"/>
<Module Path="Audits" Url="Docs/Audits/Information"/>
<Module Path="Audits" Url="Docs/Audits/External"/>
<Module Path="Audits" Url="Docs/Audits/Internal"/>
<Module Path="Audits" Url="Docs/Audits/Other"/>
</Elements>
Regards,
Doug "bobthebuilder" McCusker