ControlPath equivalent from DotNetNuke DnnApiController ActiveModule

177 Views Asked by At

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.

2

There are 2 best solutions below

0
Brad Bamford On BEST ANSWER

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.

1
Mitchel Sellers On

From the API's it doesn't appear so, you should know the path for this though since you are inside of your module, the only concern is if you are inside of a child portal you need the prefix, which you should be able to get. I'd just use Server.ResolveClientUrl() to get it.