In my previous post, I have explain basics overview of feature upgrade. But in some specific scenarios, like update xslt, masterpage, css files which are already deployed to libraries, it is required to write a custom code which will iterate through file content and replace it with new one. This post is not a reference for those who can easily perform actions like adding new fields to content type, adding new columns but can be referenced for those who want to replace the existing one and one does not sure about the fact that whether the file is ghostable or not.
All those files which are ghostable in library, i.e. those are deployed in library and not modified using SPD or any other SP tool, can be easily modified by feature upgrade without writing the custom code. But for other files which are present in library but moved to content database, we have to write some code to update those files.
- Open the project to update to visual studio tool.
- In project properties change Active Deployment Configuration to Upgrade Solution (CKSDev)
- Save the UpgradeHelper_cs
- Next step is to add file (as link) UpgradeHelper.cs to the project.In Solution Explorer right click on Project -> Add -> Existing Item -> Navigate to <Solution Folder>/CommonClasses -> Select file UpgradeHelper.cs -> Click Add
- Change Feature Manifest file to update the version of the feature: <?xml version=”1.0″ encoding=”utf-8″ ?><Feature xmlns=”http://schemas.microsoft.com/sharepoint/” ImageUrl=”REC.Direct\rec-direct-feature.png” Version=”18.104.22.168″><UpgradeActions><VersionRange BeginVersion=”0.0.0.0″ EndVersion=”22.214.171.124″><CustomUpgradeAction Name=”UpdateAllModules”></CustomUpgradeAction></VersionRange></UpgradeActions></Feature>
- Last step is to override FeatureUpgrading method in Feature Receiver class
public override void FeatureUpgrading(SPFeatureReceiverProperties properties, string upgradeActionName, System.Collections.Generic.IDictionaryparameters)
var definitions = properties.Definition.GetElementDefinitions(CultureInfo.CurrentCulture);
using (var site = (SPSite)properties.Feature.Parent)
if (upgradeActionName == "UpdateAllModules")
private static void UpdateAllModules(SPElementDefinitionCollection elementDefinitions, SPSite site)
foreach (SPElementDefinition elementDefinition in elementDefinitions)
if (elementDefinition.ElementType == "Module")
Perform the following steps in order to deploy the upgraded features to the server:
1) Add solution “COB.SharePoint.Utilities.FeatureUpgradeKit.wsp” to SharePoint by executing given PowerShell command.
Add-SPSolution –LiteralPath <folder path>/COB.SharePoint.Utilities.FeatureUpgradeKit.wsp
2) Deploy COB.SharePoint.Utilities.FeatureUpgradeKit.wsp package globally by navigating to
“Central Administration> System Settings> Manage farm solutions” then click on the solution name and then click on Deploy Solution.
3) Update existing deployed solution using PowerShell. In order to upgrade first
- Open the management PowerShell (Start> All Programs>Microsoft Sharepoint 2010 Products> SharePoint 2010 Management Shell)
- Run the following command:
Update-SPSolution –LiteralPath <folder path>/SPSolution <Solution name>
4) Feature Upgrade: Once solution was updated on the SharePoint farm next is to upgrade the features which were modified during the development. Perform following steps to upgrade the feature:
- Navigate to feature upgrade page: Central Administration -> System Settings -> Manage Feature upgrades
- Appropriately select an option in Select Feature scope to query for Web-application/Site/Web (not required for farm solutions)
- Select Only Features requiring upgrade
- Click Search
- Select the appropriate features to upgrade and click Upgrade Feature
Happy Sharepointing 🙂