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

Advertisement
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>

    [Guid("b51ec13e-683e-482f-8867-daa8afeecdd9")]
    public class Feature1EventReceiver : SPFeatureReceiver
    {
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            try
            {
                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;

                list.Update();
            }

            catch (Exception e)
            {
                throw e;
            }
        }
    }
}

Advertisements
SHARE

Lakshmi Tulasi Jasti

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

0 comments:

Post a comment