Build SharePoint Feature to Deploy File System Changes

With SharePoint solution packages, it’s possible to port the file system changes and providing Feature-based solutions! Let us build a SharePoint 2007 feature to deploy file system changes (12 hive files) using WSP Builder. Here are the steps:

1. Create a new WSP project ( you need to have WSP Builder installed. If not, get it from CodePlex)

create new sharepoint project

2. Add a New Item

add new item to project

 3. Add a New Feature with Receiver code.

add new Item
Project

2. Add the code in Feature Receiver, Say for e.g. I’m replacing an image in 12 hive, I’ve written the following code.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using System.IO;

namespace FileSystemChangesFeature
{
    class FileSystemChangesFeature : SPFeatureReceiver
    {
    public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            //Backup the Original Image NORESULT.gif and Replace with the New image from Features Directory
       if (File.Exists("C:\\Program Files\\Common Files\\Microsoft Shared\\web server extensions\\12\\TEMPLATE\\LAYOUTS\\1033\\IMAGES\\NORESULT.GIF"))
            {
               File.Move("C:\\Program Files\\Common Files\\Microsoft Shared\\web server extensions\\12\\TEMPLATE\\LAYOUTS\\1033\\IMAGES\\NORESULT.GIF","C:\\Program Files\\Common Files\\Microsoft Shared\\web server extensions\\12\\TEMPLATE\\LAYOUTS\\1033\\IMAGES\\NORESULT.GIF.BAK");
                File.Copy("C:\\Program Files\\Common Files\\Microsoft Shared\\web server extensions\\12\\TEMPLATE\\FEATURES\\FileSystemChangesFeature\\NORESULT.GIF", "C:\\Program Files\\Common Files\\Microsoft Shared\\web server extensions\\12\\TEMPLATE\\LAYOUTS\\1033\\IMAGES\\NORESULT.GIF");
            }
        }


        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            if (File.Exists("C:\\Program Files\\Common Files\\Microsoft Shared\\web server extensions\\12\\TEMPLATE\\LAYOUTS\\1033\\IMAGES\\NORESULT.GIF"))
            {
                File.Delete("C:\\Program Files\\Common Files\\Microsoft Shared\\web server extensions\\12\\TEMPLATE\\LAYOUTS\\1033\\IMAGES\\NORESULT.GIF");
                File.Copy("C:\\Program Files\\Common Files\\Microsoft Shared\\web server extensions\\12\\TEMPLATE\\LAYOUTS\\1033\\IMAGES\\NORESULT.GIF.BAK", "C:\\Program Files\\Common Files\\Microsoft Shared\\web server extensions\\12\\TEMPLATE\\LAYOUTS\\1033\\IMAGES\\NORESULT.GIF");
            }
        }

        public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        {
            //throw new Exception("The method or operation is not implemented.");
        }


        public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        {
            // throw new Exception("The method or operation is not implemented.");
        }
      }
}

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

One thought on “Build SharePoint Feature to Deploy File System Changes

  • August 1, 2014 at 8:52 PM

    what is the aim of this tips ?
    More screen print to imagine

    Reply

Leave a Reply