This post may help (I have not tried it but you might be able to adapt the approach for the file manager):
http://world.episerver.com/Blogs/Anders-Hattestad/Dates/2011/6/How-to-change-context-menu-in-the-edit-mode-tree-view/
Hi David,
Thanks, thats actually the approach I've used. The reflection isn't necessary as ActionWindow inherits pagebase and thus exposes a ContextMenu property - problem is its always null in the PageSetup event handler. I'm guessing I'm trying in the wrong time in the lifecycle or the ContextMenu is possibly set on a PlugIn contained within the ActionWindow object?
You can try hooking in on PreRender using an init module. (untested) Example below:
[InitializableModule]
[ModuleDependency((typeof(EPiServer.Web.InitializationModule)))]
public class AddContextMenu : IInitializableHttpModule
{
private static bool _loaded = false;
public void InitializeHttpEvents(System.Web.HttpApplication application)
{
application.PreRequestHandlerExecute += context_PreRequestHandlerExecute;
}
private void context_PreRequestHandlerExecute(object sender, EventArgs e)
{
//Get the Request handler from the Context
HttpContext context = ((HttpApplication)sender).Context;
//Check if the request handler is a PageBase object
if (context.Handler is EPiServer.PageBase)
{
PageBase pageBase = (PageBase)context.Handler;
pageBase.PreRender += page_PreRender;
}
}
private void page_PreRender(object sender, EventArgs e)
{
if (sender is ActionWindow)
{
// Code to hook into menu here
}
}
public void Initialize(EPiServer.Framework.Initialization.InitializationEngine context)
{
//throw new NotImplementedException();
}
public void Preload(string[] parameters)
{
throw new NotImplementedException();
}
public void Uninitialize(EPiServer.Framework.Initialization.InitializationEngine context)
{
//throw new NotImplementedException();
}
}
Thanks again David, unfortunately no luck! I definitely think I'm going about this the wrong way and assume the context menu when right-clicking on a file is actually being set somewhere in EPiServer.UI.Hosting.VirtualPathFileManager, just can't see where. I think I'm going to try a different approach that doesn't involve affecting this context menu.
Hi,
I'm trying to add an item to the context menu when right-clicking on a file in the file manager but I'm having issues getting a hold of the current context menu object. I've hooked into PageBase.PageSetup and also ActionWindow.PageSetup events to get the context menu but it is always null which leads me to believe I'm barking up the wrong tree.
Can anyone point me in the right direction?
Thank you