Pages

Search This Blog

Friday, December 9, 2011

Enable Item Scheduling through code in SharePoint 2010


Many a times we need to create lists or sites from object model and hence it is often required to enable scheduling on list. Following code will do 3 things that are required to item scheduling:

  1. Enable Content approval
  2. Enable Versioning
  3. Enable Scheduling

Scheduling is dependent on both versions and content approval and should be enabled first.

Scheduling feature is only available in publishing site.


 using (SPSite site = new SPSite("http://sharepoint2010/"))
            {
                using (SPWeb web = site.RootWeb)
                {
                    SPList list=web.Lists["Documents"];
                    list.EnableModeration = true;
                    list.EnableMinorVersions = true;
                    list.Update();
                    Microsoft.SharePoint.Publishing.PublishingWeb.EnableScheduling(list);
                }
            }


list.EnableModeration = true; code will be actually doing the setting shown below:


list.EnableMinorVersions = true; this code will enable the minor versioning on the list as shown below:



Microsoft.SharePoint.Publishing.PublishingWeb.EnableScheduling(list); This code will actually enable scheduling on this list




To disable Scheduling in the list we can use following command:

Microsoft.SharePoint.Publishing.PublishingWeb.DisableScheduling(list);

###############################################################

We can also make use of powershell script for the same

$list= $SPList = Get-SPList -url "http://sharepoint2010/" -List Documents
$list.EnableModeration=$true
$list.EnableMinorVersions=$true
# To enable Scheduling in the list
[Microsoft.SharePoint.Publishing.PublishingWeb]::EnableScheduling($list)
# To disable Scheduling in the list
[Microsoft.SharePoint.Publishing.PublishingWeb]::DisableScheduling($list)


No comments:

Post a Comment