Often companies have certain standards around version which they would like maintained when users work with documents, this post explains how to specify the document library versioning options in a document library feature.
Lets take the following scenario: A client wants all document libraries that are created to have the following settings in place:
- Document library must allow multiple content types.
- Document library must force users to check the document out before changes are made.
- Document library must maintain 5 Major versions of each document.
- Document library must maintain 5 Minor versions of each major version.
This is actually very easy and only requires a minor code addition :)
Lets go:
- Go to your custom document library feature and open the SCHEMA.xml file (features\customFeature\doclib\schema.xml).
Look for the following code:
<?xml version="1.0" encoding="utf-8"?>
<List xmlns:ows="Microsoft SharePoint" Title="$Resources:shareddocuments_Title;" Direction="$Resources:Direction;" Url="Shared Documents" BaseType="1">
<Metadata>
Note: The above code is taken from the default document library so yours may differ - the area where we are going to add our code is within the <List> tag.
- You want to add the following bits of code in the <List> tag:
<?xml version="1.0" encoding="utf-8"?>
<List xmlns:ows="Microsoft SharePoint" Title="$Resources:shareddocuments_Title;" Direction="$Resources:Direction;" Url="Shared Documents" BaseType="1"
EnableContentTypes="TRUE" ForceCheckout="TRUE" EnableMinorVersions="TRUE" VersioningEnabled="TRUE" MajorVersionLimit="5" MajorWithMinorVersionsLimit="5" >
Note: The code additions are pretty self explanetory!
- Save, IISRESET (or enable your feature), create the document library.
IMPORTANT: when creating the document library ensure to select "Create a version each time you edit a document" - otherwise your versioning settings will be overwritten!
When created automatically via template though, the activation the settings will be in place.
- View the versioning settings. Happy days :)
UPDATE:
Here are some more settings you can include:
- If you want to ensure that only users who have "edit" rights on documents can view draft versions of documents:
DraftVersionVisibility="1" ("0" for read access)
Regards,
Doug "bobthebuilder" McCusker