Pre-Populating Folder(s) in Document Library with the Help of List Instance Definition


Scenario:

Today when I was working on a requirement, I had the need to create a customized picture library. To create this picture library the required List Schema, Definition, Instance Template, etc. were created.

Challenge:

One challenge I had at the end was, that this Library had to be pre-populated with a folder to store some control files.
Here is how it was resolved:

Note: I will not explain how the list definition and schema were created as there are several posts out there to help.

Solution:

In the List Instance definition (manifest file), you just have to add the line shown below (Module.. Path..):

   1:  <?xml version="1.0" encoding="utf-8" ?>
   2:  <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
   3:   
   4:    <ListInstance FeatureId="327B763B-A5E7-4ac2-8458-B6570D362C0B"
   5:                 Id="WattsUpImagesLibrary"
   6:                 Title="$Resources:MyResource,ListInstance_WattsUpImages_DisplayName"
   7:                 Description="$Resources:MyResource,ListInstance_WattsUpImages_Description"
   8:                 Url="WattsUpImagesLibrary"
   9:                 TemplateType="3111" 
  10:                 OnQuickLaunch="FALSE" />
  11:    <!-- Adding a folder to the list instance-->
  12:    <Module Path="ControlFiles" Url="WattsUpImagesLibrary/ControlFiles" />
  13:  </Elements>

Please take a special note of the URL attribute, the value “WattsUpImagesLibrary” is the one used above as URL of the instance.

The output as a result of this:

image

IMPORTANT: To be able to create folder in Document Library, your list need to have the content reference of “0x0120” OR a custom one derived from it in the format of 0x0120 + 00 + <Guid>

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.