Created
June 1, 2012 02:59
-
-
Save SitefinityGuru/2848319 to your computer and use it in GitHub Desktop.
Install Widgets for your Sitefinity Module during Module Installation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public override void Install(SiteInitializer initializer) | |
{ | |
#region Install Toolbox Widgets | |
// get section from toolbox | |
var config = initializer.Context.GetConfig<ToolboxesConfig>(); | |
var pageControls = config.Toolboxes["PageControls"]; | |
var section = pageControls | |
.Sections | |
.Where<ToolboxSection>(e => e.Name == ToolboxesConfig.ContentToolboxSectionName) // Or other section eg: "NavigationControlsSection" | |
.FirstOrDefault(); | |
// add widget to section if it doesn't exist | |
if (!section.Tools.Any<ToolboxItem>(e => e.Name == "MY_CONTROL_NAME")) | |
{ | |
var tool = new ToolboxItem(section.Tools) | |
{ | |
Name = "MY_CONTROL_NAME", | |
Title = "Title of Control", | |
Description = "Description of control", | |
ControlType = "~/Virtual/Path/To/Control.ascx", | |
ModuleName = "Module_Name_Optional", | |
CssClass = "CSS-class-optional" | |
}; | |
section.Tools.Add(tool); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Because this is executed during the module installation, you don't need to call SaveChanges(). The SiteInitializer will do this automatically if the module is successfully installed (or rollback all changes if it fails). For more, visit http://www.selarom.net/sitefinityguru