0

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.

Brad Bamford
  • 3,783
  • 3
  • 22
  • 30

2 Answers2

1

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.

Brad Bamford
  • 3,783
  • 3
  • 22
  • 30
0

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.

Mitchel Sellers
  • 62,228
  • 14
  • 110
  • 173
  • You're right that one "should know". However, I prefer to reuse this in a library across every module I make, regardless if it's a standard module, in a sub directory, or an MVC module etc – Brad Bamford Mar 23 '17 at 14:00