SharePoint · SharePoint 2010 · SharePoint 2013

SharePoint 2013 – Update Features


My Problem

Today I needed to add some additional fields to content types. I heard about upgrade features before, but I never tried using this.

It was quite simple.

First I added a version number to the feature:

Version=”2.0.0.1″

Then I added some Upgrade actions:

Now running an Update-SPSolution to install the new solution does … absolutely nothing to my site.

Your Solution

Each feature with upgrades need to have a feature upgraded.this can be done with the SPFeature.Upgrade() method.

So I created another feature, which upgrades my content type feature.

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{

try
{

SPSite site = properties.Feature.Parent as SPSite;
if (site != null)
{

foreach (SPFeature feature in site.Features)

{
if (feature.DefinitionId.ToString() == “119ea7f0-da08-4d6b-8c0f-0706240bfc5a”)
{

// Upgrade the Contenttype and custom columns feature
feature.Upgrade(true);

}

}

}
catch (Exception Ex)
{

LoggingService.WriteTrace(“FeatureUpgrade”, TraceSeverity.Unexpected, Ex.Message);

}

}

Still quite a tricky problem.

When you run Update-SPSolution the new feature doesn’t appear. You first need to uninstall and reinstall the solution. This will now add the new feature. But now when I activate my feature again absolutely nothing happens.

I had to update the version number of my feature again

Version=”2.0.0.2″

Run Update-SPSolution and my changes have come through after I activate my new feature.

Advertisements

Please leave a comment or feedback

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s