Friday, March 4, 2011

Build SharePoint Feature to Deploy File System Changes

With SharePoint solution packages, its possible to port the file system changes and providing Feature based solutions! Lets 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)

2. Add a New Item


 3. Add a New Feature with Receiver code.



2. Add the code in Feature Receiver, Say for e.g. I'm Replacing a 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.");
        }
      }
}



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Five Challenges in SharePoint Security
...And How to Solve Them. Free White Paper
*Sponsored


Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...