Default Versions in SharePoint

How do I change a SharePoint site so that version control is enabled by default in document libraries?

+5
source share
2 answers

Versions are not run at the site level, but at the list level.

If you want version control to be included in each new library, you need to either:

  • Use your own library template (with versioning enabled)
  • Use function + event handler to programmatically activate versions in each new list

The easiest way is to use your own template. To do this, create a new document library, activate version control, then save this list as a template.

.

+7

, , , , , . , , , , - .

SharePoint. , - , . , , .

, , , "ListCreating" , . , FeatureActivated, , , , . , , .

ItemAdding . , , . , , . , , , .

, . , :

public class SetVersioning : SPItemEventReceiver
{
    public override void ItemAdding(SPItemEventProperties properties)
    {
        SPWeb CurrentWeb = properties.OpenWeb();
        foreach (SPDocumentLibrary doclib in CurrentWeb.GetListsOfType(SPBaseType.DocumentLibrary))
        {
            doclib.EnableVersioning = true;
            doclib.MajorVersionLimit = 8;
            //doclib.EnableMinorVersions = true;
            doclib.Update();
        }
        //now get rid of the receiver
        SPEventReceiverDefinitionCollection receivers = CurrentWeb.EventReceivers;
        foreach (SPEventReceiverDefinition definition in receivers)
        {
            if (definition.Name.Equals(EVENT_RECEIVER_NAME))
            {
                definition.Delete();
                break;
            }
        }

        base.ItemAdding(properties);
    }
}
+5

All Articles