Find a module's virtual path

Topics: User Forum
May 3, 2007 at 12:21 PM
I would like to find a module's virtual path from within the ModuleInitializer. I have not found a decent way of doing this, but I do not want to hardcode the path when I'm building up the sitemap in RegisterSiteMapInformation(). Anyhow who knows how to do it?
Developer
May 3, 2007 at 3:23 PM
Edited Jun 7, 2007 at 8:48 PM
Hi, to find a module’s virtual path, what you should do is use the WebModuleEnumerator service. This service gets the module metadata from the modules configuration files.

To retrieve the service that implements the IModuleEnumerator interface (By default the WebModuleEnumerator) put in your Load method of the ModuleInitializer the following:
IModuleEnumerator moduleEnumerator = moduleContainer.Services.Get<IModuleEnumerator>(true);
And to get the modules metadata you have to call the EnumerateModules method of this service:
IModuleInfo[] modules = moduleEnumerator.EnumerateModules();
Now you can iterate by the modules and look at the info you need.

For your convenience here is the IModuleInfo interface:
public interface IModuleInfo
{
     /// <summary>
     /// Gets the module name.
     /// </summary>
     string Name { get; }
 
      /// <summary>
      /// Gets the module assembly.
      /// </summary>
      string AssemblyName { get; }
 
      /// <summary>
      /// Gets the virtual path to the module location.
      /// </summary>
      string VirtualPath { get; }
}
Please let me know if this helps,
Ezequiel Jadib
http://staff.southworks.net/blogs/ejadib