Custom field in the GridContextMenu. Pass the selected item's path to the server when the field is clicked.

Add custom field in the GridContextMenu and implement the server functionality when that field is clicked. The problem is passing the path of the selected item to the server. The RadFileExplorer control does not have server property that holds the currently selected file's path. The CurrentFolder property is similar, but it holds the path to the currently selected directory.
We need to use some client-side and server-side scripts in order to achieve the desired result.

The first approach :

Create a RadMenuItem and add it to the GridContextMenu's item collection :
C# :

RadMenuItem item = new RadMenuItem("UnZip");

item.PostBack = false;

item.Value = "CustomValue";

RadFileExplorer1.GridContextMenu.Items.Add(item);

VB.NET :

Dim item AsNew RadMenuItem("UnZip")

item.PostBack = False

item.Value = "CustomValue"

RadFileExplorer1.GridContextMenu.Items.Add(item)

Attach a handler to the GridContextMenu''s OnClientItemClicked event as follows :
C# :

Add an RadAjaxPanel to the page. Attach a server handler to the OnAjaxRequest event. Please note that you can use different approach in this step (for example __doPostBack() function instead of the ajax request).

Implement the OnGridContextItemClicked function as follows :

<script type="text/javascript">

function OnGridContextItemClicked(oGridMenu, args)

{

var menuItemText = args.get_item().get_text();

if (menuItemText == "UnZip")

{// 'UnZip' command

var oExplorer = $find("<%= RadFileExplorer1.ClientID %>");

var oAjaxPanel = $find("<%= RadAjaxPanel1.ClientID %>");

var selectedItem = oExplorer.get_selectedItem();

if (selectedItem)

{

var itemPath = selectedItem.get_path(); // get the path of the current item

oAjaxPanel.ajaxRequest(itemPath); // Call the RadAjaxPanel1_AjaxRequest function on the server ;

}

else

{

alert("Please, selct an item");

}

}

}

</script>

Inside of this function we found the RadFileExplorer's client-side object and use its API in order to get the selected item. Then we trigger an AJAX request to the server and pass the path to the selected file as a parameter of the ajaxRequest() function.

Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks for appropriate markings.