0

I have created a feature, a publishing site, in Visual Studio to MOSS - this feature contains some custom list templates and some lists using the template definitions. Now I need to update the list templates, which is not a problem as it is just adding af few lines to my schema.xml, but I need a way to reflect the update on the existing lists also.

As far as i know this feature is not standard Sharepoint, but how can I programatically work around this e.g. ny in my OnActivated, loop through my list and update (delete/add) the fields based on the template of the list?

keysersoze
  • 777
  • 3
  • 12
  • 27

1 Answers1

0

Yes, when you update list schema, it will not reflect in already created list. For this, add a FeatureActivated event handler in your schema. This event handler will run a code whenever you activate your feature.

Create a XML configuration file in your Feature which will contain the list names which are already created. The code will then read the XML file and update your lists which are already created.

For extensibility and flexibility, Note that this code needs to be as defensive as possible. For ex , when you again activate the feature again sometime in future it should not make the change again resulting in loss or duplicacy of changes. It should first check and then only make the change.

The same scheme can be used for content types. If required I can post a code snippet for you.

 public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        try
        {
            // Fix the Article Date column
            if (properties != null)
            {
                FixArticleDate(properties);
            }

            // Fix Metadata Tagging site columns by setting CustomField "MetadataType" to the Default value set in the field definition manifest file.
            if (properties != null && properties.Feature.Properties["FixMetadataTagging"] != null)
            {
                RepairMetadataTaggingSiteColumns(properties);
            }

            // Fix Lookup site columns by retrieving lookup list GUID from List="url". 
            if (properties != null && properties.Feature.Properties["FixListTagging"] != null)
            {
                RepairListTaggingSiteColumns(properties);
            }

            // Fixing Site Columns
            if (properties != null && properties.Feature.Properties["FixSiteColumns"] != null)
            {
                RepairSiteColumns(properties);
            }
        }
        catch (SPException sharepointEx)
        {
            ExceptionManager.LogError(ULSTracerCategoriesEnum.FeatureReceivers, sharepointEx);
        }
    }

XML:

<?xml version="1.0" encoding="utf-8" ?>
<Feature Id="A23990CF-C35D-4771-BF5A-916C304C9EF9"
   Title="Content Types"
   Description="This Feature Creates all the Required Content Types and site columns"
   Version="1.0.0.0" Scope="Site" Hidden="FALSE"
   ReceiverAssembly="xxxx, Version=1.0.0.0, Culture=neutral, PublicKeyToken=86597c5d57921943"
   ReceiverClass="xxxx.SharePoint.UI.Core.FeatureReceivers.CoreFeatureReceiver"        
   xmlns="http://schemas.microsoft.com/sharepoint/">
  <ElementManifests>
    <ElementManifest Location="SiteColumns\SiteColumns.xml" />
    <ElementManifest Location="ContentTypes\ContentTypes.xml" />
  </ElementManifests>
  <Properties>
    <Property Key="FixMetadataTagging" Value="SiteColumns\MetadataTaggingSiteColumnsManifest.xml"/>
    <Property Key="FixListTagging" Value="SiteColumns\ListTaggingSiteColumnsManifest.xml"/>
    <Property Key="FixSiteColumns" Value="ContentTypeFixes\SiteColumnAdditions.xml"/>
  </Properties>
</Feature>
Madhur Ahuja
  • 22,211
  • 14
  • 71
  • 124
  • with the given code i guess that I in the repair-methods will have to find missing fields and add them by using MySPList.Fields.Add? – keysersoze Jan 10 '11 at 14:37
  • yes, basically, whatever you want. Put the data in xml, like your field names, and read it in code and do the operation. Make sure its defensive, means, make sure you dont end up adding same fields again and again just by activating feature again and again – Madhur Ahuja Jan 10 '11 at 16:15
  • maybe its much to ask, but is it possible that you can give som extra clues because nothing I try is a success. If I look at the Fields of an existing list all fields are included - if I look at the contenttype of my list I can se that the new fields are missing, but I cannot find a way to add the missing fields? – keysersoze Jan 11 '11 at 15:23
  • Sorry for my late response - I got some other tasks that needed to be solved. In the meantime I found a solution; by building my custom fields plus my content type "standalone" and associate the content type to my custom list (instead of just adding the fields to my custom list) changes to the content type are now reflected down to lists created from the custom list without any code. Thanks a lot for your input :) – keysersoze Jan 19 '11 at 12:37