Automatic content provisioning to your SharePoint site

Whether your still testing your future SharePoint site or ready to make a first QA or Prod deployment – you probably need to ship some content and not just empty sites. Even you landing pages pictures will have to be stored in document libraries; you also may need some lists created along with list items in them.

There is two ways to provision such content to your site. Today I`ll talk about first approach.

If you`re creating document library (for example) and would like to see few files copied into it along the way, this is how you do it

Create a feature in your SharePoint solution with the content similar to this:

<?xml version=”1.0″ encoding=”utf-8″?>

<Feature xmlns=”http://schemas.microsoft.com/sharepoint/”

Id=”C9FB4590-08F2-4655-B1DF-5E1BE3F13773″
Title=”Provision Content”
Description=”Provisions Initial Content”
Version=”1.0.0.0″
Scope=”Web”
Hidden=”TRUE”
ActivateOnDefault=”FALSE”
AlwaysForceInstall=”TRUE”
ImageUrl=”">
<ElementFile Location=”Images/MyImage.jpg” />
<ElementManifest Location=”ItemsToProvision.xml” />
<ElementManifest Location=”ListsToProvision.xml” />
</Feature>

In here I take an image MyImage.jpg from the Images folder and copy it to the package. My ItemsToProvision.xml defines where to provision my file; and here is how it looks like:

<?xml version=”1.0″ encoding=”utf-8″?>

<Elements xmlns=”http://schemas.microsoft.com/sharepoint/”>
<Module Name=”Images” Url=”Lists/My Picture Library” Path=”Images”>
<File Url=”MyImage.jpg” Type=”GhostableInLibrary” >
<Property Name=”Title” Value=”My Picture Title” />
</File>
</Module>
</Elements>

You noticed I still have to create My Picture Library within my site, which is handled by ListsToCreate.xml from above and here is how that one looks like:

<?xml version=”1.0″ encoding=”utf-8″ ?>

<Elements xmlns=”http://schemas.microsoft.com/sharepoint/”>

<ListInstance FeatureId=”1435C2C1-0423-4583-9F98-55200607A316″

Title=”My Picture Library”

Description=”Picture Library”

TemplateType=”109″

Url=”Lists/My Picture Library”/>

</Elements>

In here the only thing that needs explaining is TemplateType – will depend on what type of library you`re creating. Regular Document Library for instance is 101

That`s all, when your feature activates – My Picture Library will be created and MyImage.jpg placed into it with associated property values.

In my next article I show how to create items in lists and libraries that already exist and come out of the box as you create your site.

This entry was posted in MOSS, sharepoint, wss and tagged , , . Bookmark the permalink.

Comments are closed.