moopoo.net
Fishing, technology and anything else

Adding element to web.config on feature activation

March 15th, 2010 by Matt
public override void FeatureActivated(SPFeatureReceiverProperties properties) {
 
            SPSite site = (SPSite)properties.Feature.Parent;
 
            SPWebConfigModification controlsSection = new SPWebConfigModification("controls", "configuration/system.web/pages");
            controlsSection.Owner = "My.Menu";
            controlsSection.Sequence = 20;
            controlsSection.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureSection;
            controlsSection.Value = "<controls></controls>";
 
            SPWebConfigModification addElement = new SPWebConfigModification(
                @"add[@tagPrefix=""SharePoint""][@namespace=""My.Menu""][@assembly=""My.Menu, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cd3368f0ff736bff""]", 
                "configuration/system.web/pages/controls");
            addElement.Owner = "My.Menu";
            addElement.Sequence = 40;
            addElement.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
            addElement.Value = @"<add tagPrefix=""SharePoint"" namespace=""My.Menu"" assembly=""My.Menu, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cd3368f0ff736bff"" />";
 
            site.WebApplication.WebConfigModifications.Add(controlsSection);
            site.WebApplication.WebConfigModifications.Add(addElement);
            site.WebApplication.Update();
            site.WebApplication.WebService.ApplyWebConfigModifications();
 
    }

Posted in SharePoint

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.