
Februarie 11, 2015 17:38 by
Mark
Uninstall DNN Module programmatically
To uninstall the DNN module is actually quite complex via code. There are couple of table modules related and depends on each other. Fortunately, the DNN framework has a built in delete method for these modules. There are 3 tables in the database that are related to the module definitions. They are: DesktopModules, ModuleDefinitions and PortalDesktopModules. The DesktopModules and ModuleDefinitions tables are global tables that are linked to all portals. While PortalDesktopModules table contains a relationship between each portals and what modules can be used by each individual portal.
Lets say you want to remove a list of modules containing a name started with MyModule_.
/* Firstly, you need to include these namespaces on the top of the code */
/* This namespace for Dictionary collection */
using System.Collections;
/* These namespaces for module collection */
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Definitions;
The next part is to grab a list of module definitions collection and compare if the name contains MyModule_
/* Declare ModuleDefinitionController object */
ModuleDefinitionController objModuleDefinitionController = new ModuleDefinitionController();
/* Declare DesktopModuleController object */
DesktopModuleController objDesktopModuleController = new DesktopModuleController();
/* Get dictionary module collection */
Dictionary<int, ModuleDefinitionInfo> moduleList = ModuleDefinitionController.GetModuleDefinitions();
/* Perform a looping in the module list */
foreach (int i in moduleList.Keys) {
/* We only delete the module friendly name contains MyModule_ */
if (moduleList[i].FriendlyName.IndexOf("MyModule_") >= 0) {
/* Delete the module from table module definitions */
objModuleDefinitionController.DeleteModuleDefinition(moduleList[i].ModuleDefID);
/* Delete the module from table desktop modules */
objDesktopModuleController.DeleteDesktopModule(moduleList[i].DesktopModuleID);
/* Delete the module from portal desktop modules */
DesktopModuleController.RemoveDesktopModuleFromPortal(PortalId, moduleList[i].DesktopModuleID, true);
}
}
Best Recommended DotNetNuke Hosting
ASPHostPortal.com
ASPHostPortal.com is the leading provider of Windows hosting and affordable DotNetNuke Hosting. DotNetNuke Hosting from ASPHostPortal.com provides a safe, reliable and performance-driven foundation for your DotNetNuke website. DotNetNuke is the perfect Content Management System for managing and developing your website with one of ASPHostPortal’s Hosting plans. ASPHostPortal has ability to support the latest Microsoft and ASP.NET technology, such as: WebMatrix, WebDeploy, Visual Studio 2015, .NET 5/ASP.NET 4.5.2, ASP.NET MVC 6.0/5.2, Silverlight 6 and Visual Studio Lightswitch, ASPHostPortal guarantees the highest quality product, top security, and unshakeable reliability, carefully chose high-quality servers, networking, and infrastructure equipment to ensure the utmost reliability.