Programmatically enabling the contentmanagement,versioning,content approval for documents in sharepoint

In this article I will explain how to create Programmatically enabling the contentmanagement,versioning,content approval for documents.

First I created a empty share point solution,In that we can able to see the Features,Right click AddFeature In  Feature1EventReceiver write the below code,once we deploy I will enable automatically.

using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;

namespace DOCUMENT.Features.Feature1
    /// <summary>
    /// This class handles events raised during feature activation, deactivation, installation, uninstallation, and upgrade.
    /// </summary>
    /// <remarks>
    /// The GUID attached to this class may be used during packaging and should not be modified.
    /// </remarks>

    public class Feature1EventReceiver : SPFeatureReceiver
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
                SPWeb web = properties.Feature.Parent as SPWeb;
                SPList list = web.Lists["ListName"];
//enabling the content management
                list.ContentTypesEnabled = true;
//enable both major and minor versioning
                list.EnableVersioning = true;
                list.EnableMinorVersions = true;
//Enabling content approval for the documents
                list.EnableModeration = true;
//draft version visiblity of the documents.
                list.DraftVersionVisibility = DraftVisibilityType.Approver;


            catch (Exception e)
                throw e;


Lakshmi Tulasi Jasti

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment


Post a Comment