Question

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?

Was it helpful?

Solution

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top