Posted by: wming | August 7, 2008

How to programmatically enable scheduling (part I)

One of my current task is to enable scheduling for existing 44 document/list libraries. All of these document/list library has only one content type associated with and it was inherited from a base content type. However, Sharepoint default site column Scheduling Start Date and Scheduling End Date are not included in the base content type. To accomplete the task, you can use Sharepoint to configure this manually, steps as following
1. add Scheduling Start Date and Scheduling End Date to the library
2. enable versioning
3. enable scheduling
4. repeat 44 times

Apparently, this is not a good idea. If we need rebuild the site from scratch, that means you have to repeat step 1-4 again. So, put on developer’s hat:

My first thought is to add Sharepoint default Scheduling Start Date and Scheduling End Date site column to the base content type. I have my content type xml already, so I added the following

    <FieldRef Name=”SchedulingStartDate”
    DisplayName=”Scheduling Start Date”
    ID=”{51d39414-03dc-4bd0-b777-d3e20cb350f7}”
    />

   <FieldRef Name=”SchedulingEndDate”
    DisplayName=”Scheduling End Date”
    ID=”{a990e64f-faa3-49c1-aafa-885fda79de62}”
    />

The only trick is how to find the default guid. Go to site setting->content type->click any of the site content type include above fields (for example: Generic Content->Scheduling Start Date). The browser address bar ends like Fid=%7B51d39414%2D03dc%2D4bd0%2Db777%2Dd3e20cb350f7%7D, replace %7B with “{“, %2D with “-”, %7D with “}”, the guid is {51d39414-03dc-4bd0-b777-d3e20cb350f7}.

Well, build and deploy, those 2 fields successfully added to my base content type. But wait….this does not solve my problem yet. Oops, those 44 document/list library does not change at all because they are there ALREADY….my changing of base content type only work for those NEW document/lists, not for the existing one. Rather than write your own code, Sharepoint actually has a option to let you update all inherited content types when you add/delete site column from its parent content type. You could go to site setting->modify site setting -> content type -> select the base content type -> add fields from existing site column. Make sure “update inheritate content type” check box is checked. Also, do this manual step before you install the solution. Ok, the 2 extra fields were added to all the document library after this…(in my case, all content library inheriated from the base content type). But, to enable scheduling, you have to enable versioning and scheduling. Instead of do it manually, I decide create a feature to loop through all document library and enable scheduling.

To be continue…


Leave a response

Your response:

Categories