Click here to Skip to main content
15,895,084 members
Articles / Web Development / ASP.NET

SharePoint Feature to Extend SharePoint Site with AJAX 3.5 and Telerik Rad Controls

Rate me:
Please Sign up or sign in to vote.
4.67/5 (2 votes)
21 Sep 2009CPOL4 min read 57.8K   301   17  
This article explains how to create SharePoint feature to extend SharePoint site with AJAX 3.5 and Telerik Rad Controls.

This article appears in the Third Party Products and Tools section. Articles in this section are for the members only and must not be used to promote or advertise products in any way, shape or form. Please report any spam or advertising.

using System.Collections.Generic;
using System.Xml;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace DeploymentFeature.WebConfigModification
{
    /// <summary>
    /// FeatureEventReceiver class traps the activation, deactivation, installation,
    /// or uninstallation of a Feature. 
    /// </summary>
    [System.ComponentModel.Category("1A995AC4-81CE-469B-B8C8-106019226740")] //Don't remove! This attribute is added by SPVisualDev to bind it to a WSS feature ID.
    public class FeatureEventReceiver : SPFeatureReceiver
    {
        #region Constructors

        /// <summary>
        /// Initializes a new instance of the Microsoft.SharePoint.SPFeatureReceiver class.
        /// </summary>
        public FeatureEventReceiver()
        {
        }

        #endregion // Constructors

        #region Properties

        /// <summary>
        /// Gets or sets the deployment nodes.
        /// </summary>
        /// <value>The deployment nodes.</value>
        private XmlNodeList DeploymentNodes { get; set; }

        /// <summary>
        /// Gets or sets the collection of DLLs to be installed into the GAC.
        /// </summary>
        /// <value><see cref="Dictionary"/> of dlls.</value>
        private Dictionary<string, string> DllsToGac { get; set; }

        #endregion // Properties

        #region Methods

        private void ReadDeploymentSettings(SPFeatureReceiverProperties properties)
        {
            // Open the reader with the source XML file
            XmlTextReader reader = new XmlTextReader(properties.Definition.RootDirectory + @"\..\..\LAYOUTS\WebConfigModification\DeploymentSettings\RadControlsWebConfigAdds.xml");

            // Load the source of the XML file into an XmlDocument
            XmlDocument mySourceDoc = new XmlDocument();

            // Load the source XML file into the first document
            mySourceDoc.Load(reader);

            // Close the reader
            reader.Close();

            XmlNode root = mySourceDoc.SelectSingleNode("WebConfigDeployments");

            XmlNodeList dllsToGac = root.SelectNodes("DllToGac");
            this.DeploymentNodes = root.SelectNodes("Deployment");

            this.DllsToGac = new Dictionary<string, string>();

            foreach (XmlNode dllToGac in dllsToGac)
            {
                this.DllsToGac.Add(dllToGac.Attributes["Name"].Value, dllToGac.Attributes["Folder"].Value);
            }
        }

        #endregion // Methods

        #region Events

        /// <summary>
        /// Occurs after a Feature is installed.
        /// </summary>
        /// <param name="properties">A Microsoft.SharePoint.SPFeatureReceiverProperties object that represents properties of the event handler.</param>
        public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        {
        }

        /// <summary>
        /// Occurs after a Feature is activated.
        /// </summary>
        /// <param name="properties">A Microsoft.SharePoint.SPFeatureReceiverProperties object that represents properties of the event handler.</param>
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            this.ReadDeploymentSettings(properties);

            SPWebApplication webApplication = properties.Feature.Parent as SPWebApplication;

            Installer installer = new Installer()
            {
                WebApplicationId = webApplication.Id,
                Nodes = this.DeploymentNodes,
                DllsToGac = this.DllsToGac
            };

            installer.Deploy(Installer.DeploymentType.Deploy);
        }

        /// <summary>
        /// Occurs when a Feature is deactivated.
        /// </summary>
        /// <param name="properties">A Microsoft.SharePoint.SPFeatureReceiverProperties object that represents properties of the event handler.</param>
        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            this.ReadDeploymentSettings(properties);

            SPWebApplication webApplication = properties.Feature.Parent as SPWebApplication;

            Installer installer = new Installer()
            {
                WebApplicationId = webApplication.Id,
                Nodes = this.DeploymentNodes,
                DllsToGac = this.DllsToGac
            };

            installer.Deploy(Installer.DeploymentType.UnDeploy);
        }

        /// <summary>
        /// Occurs when a Feature is uninstalled.
        /// </summary>
        /// <param name="properties">A Microsoft.SharePoint.SPFeatureReceiverProperties object that represents properties of the event handler.</param>
        public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        {
        }

        #endregion // Events
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) CPP Investment Board
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions