Skip to content

Instantly share code, notes, and snippets.

@SitefinityGuru
Created June 1, 2012 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SitefinityGuru/2848319 to your computer and use it in GitHub Desktop.
Save SitefinityGuru/2848319 to your computer and use it in GitHub Desktop.
Install Widgets for your Sitefinity Module during Module Installation
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);
}
}
@SitefinityGuru
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment