Check if a Sitefinity Module is Installed or Disabled

When working with the Sitefinity API and its various Content Managers, you need to make sure and consider the fact that after version 5.1, users have the ability to disable modules. Attempting to access the content manager of a disabled module will result in an exception such as this:

[Exception: The configuration 'EventsConfig' is not registered]
   Telerik.Sitefinity.Configuration.Config.VerifySectionRegistered(Type sectionType) +154
   Telerik.Sitefinity.Configuration.Config.GetSectionInternal(Type sectionType, Boolean safeMode) +17
   Telerik.Sitefinity.Configuration.Config.GetSectionPrivate(Type sectionType, Boolean safeMode) +130
   Telerik.Sitefinity.Configuration.Config.GetSectionPrivate(Boolean safeMode) +62
   Telerik.Sitefinity.Modules.Events.EventsManager.get_ProvidersSettings() +14
   Telerik.Sitefinity.Data.ManagerBase`1.GetProvidersSettings() +10
   Telerik.Sitefinity.Data.ManagerBase`1.Initialize() +534
   Telerik.Sitefinity.Data.ManagerBase`1..ctor(String providerName, String transactionName) +19
   Telerik.Sitefinity.Modules.Events.EventsManager..ctor() +28

When a module is disabled, that setting is stored in the SystemConfig file. So you can easily retrieve that config and check the ApplicationModules property using the Module name as an index to determine the status, which is stored in the StartupType property.

Here's an example code snippet that checks the status of the three main content modules: Blogs, News, and Events. You can replace the module name with any built-in or custom module to determine its status.

	BlogsManager blogMgr = null;
	NewsManager newsMgr = null;
	EventsManager evMgr = null;

	// retrieve the System Configuration
	var systemConfig = Config.Get<SystemConfig>();

	// blogs
	var blogModuleConfig = systemConfig.ApplicationModules[BlogsModule.ModuleName];
	if (blogModuleConfig.StartupType != StartupType.Disabled)
		blogMgr = BlogsManager.GetManager();

	var newsModuleConfig = systemConfig.ApplicationModules[NewsModule.ModuleName];
	if (newsModuleConfig.StartupType != StartupType.Disabled)
		newsMgr = NewsManager.GetManager();

	var eventsModuleConfig = systemConfig.ApplicationModules[EventsModule.ModuleName];
	if (eventsModuleConfig.StartupType != StartupType.Disabled)
		evMgr = EventsManager.GetManager();

View this code snippet on Gist.

Enjoyed this post and/or found it useful?
Tagged with:
SelArom Dot Net Profile Image
SelAromDotNet

Josh loves all things Microsoft and Windows, and develops solutions for Web, Desktop and Mobile using the .NET Framework, Azure, UWP and everything else in the Microsoft Stack.

His other passion is music, and in his spare time Josh spins and produces electronic music under the name DJ SelArom.



Scroll to top