Wednesday, September 10, 2008

Maximum Versions Settings on Lists and Document Libraries


Versioning is a powerful feature of SharePoint-based lists and document libraries.

In document library and list,every time when change the item then it taks extra sizes so database size is increase.
Many organizations may wish to limit the amount of major versions that are kept.
However, this setting is determined by each individual list - but one can easily change this setting via the WSS.
Here is the programatically you can change the limit of the maximum version through the event handler or in your webpart.

public void VersionSettingLimit(string siteUrl)
{

SPSite site = new SPSite(siteUrl);
SPWeb web = site.OpenWeb();
web.AllowUnsafeUpdates = true;
SPListCollection listColl = web.Lists;
foreach (SPList list in listColl)
{
try
{
list.MajorVersionLimit = 2;
list.Update();
}
catch (Exception setVersionException)
{
}
}
}