dotnetnukedotnetnuke-moduledotnetnuke-7

ControlPath equivalent from DotNetNuke DnnApiController ActiveModule


Is there a way to get the module root folder (folder under DesktopModules) of the ActiveModule from a DnnApiController?

In PortalModuleBase I would use the ControlPath property to get to the same root folder I'm looking for.


Solution

  • As @MitchelSellers points out, it doesn't appear to be in the API so you have to figure it out yourself. Since the API gives us the ActiveModule which is a ModuleInfo that's probably the best way to get at it.

    If your modules use a pretty standard consistent naming then the following "best guess" method should work pretty well

    public static string ControlPath(ModuleInfo mi, bool isMvc = false)
    {
        return isMvc
            ? $"/DesktopModules/MVC/{mi.DesktopModule.FolderName}"
            : $"/DesktopModules/{mi.DesktopModule.FolderName}";
    }
    

    The other way is to look at the ModuleDefinitions of our module and grab the first ModuleControl and look at it's ControlSrc to see it's path.

    public static string ControlPath(ModuleInfo mi)
    {
        var mdi = mi.DesktopModule.ModuleDefinitions.First().Value;
        var mci = mdi.ModuleControls.First().Value; // 1st ModuleControl
    
        return Path.GetDirectoryName(mci.ControlSrc);
    }
    

    The second method is really messy (and untested) but should give you the actual folder path where the controls are installed, over the other best guess method above.