Implimentation download custom button functionality in RAD File explorer

2 posts, 0 answers
  1. sandhya
    sandhya avatar
    12 posts
    Member since:
    May 2011

    Posted 31 May 2011 Link to this post

    Hi Telerik,

    In RAD File explorer grid context menu if i click on download it should download the file.How can we achieve this task.
    Is there any demo example with code .please can you share it me..

    How to get the physical path from server side.?
    I added custom download file button in grid context menu.
    This is my code:
    Client side:
    --------------

     

     

    function DownloadFileWindow(oGridMenu, args) {

     

     

     

     

    var domElem = args.get_targetElement();

     

     

     

     

    var text = $telerik.$(domElem).text();

     

     

     

     

    //var isFolder = text.indexOf(".") == -1;

     

     

     

    var gridContextMenuItems = oGridMenu.get_allItems();

     

     

     

     

    for (var i = 0; i < gridContextMenuItems.length; i++) {

     

     

     

     

    var menuItem = gridContextMenuItems[i];

     

     

     

     

    if (menuItem.get_value() == "Download_File") {

     

     

    OnClientFileOpen(sender, args)

     

    __doPostBack(

     

    "download");

     

     

    }

     

    }

     

    }


    Server side:

    radFileExplorer.GridContextMenu.OnClientItemClicked = "DownloadFileWindow";


    I am calling my function like this

     

     

    string userSelection = Request.Params.Get("__EVENTTARGET");

     

     

     

     

    if (userSelection == "download")

     

     

    {

     

    DownLoadFile();

     

    }

    private

     

     

    void DownLoadFile()

     

     

    {

     

     

     

    string TargetFile = here i need physical path of the file
    //radFileExplorer.TreeView.SelectedNode.GetFullPath("/");//radFileExplorer.Configuration.ViewPaths;

     

    System.IO.

     

    FileInfo file = new System.IO.FileInfo(TargetFile);

     

     

     

     

    //-- if the file exists on the server

     

     

     

    //set appropriate headers

     

     

     

    if (file.Exists)

     

     

    {

     

     

     

    FileStream liveStream = new FileStream(TargetFile, FileMode.Open, FileAccess.Read);

     

     

     

     

    byte[] buffer = new byte[Convert.ToInt32(liveStream.Length) + 1];

     

     

    liveStream.Read(buffer, 0,

     

    Convert.ToInt32(liveStream.Length));

     

     

    liveStream.Close();

     

    Response.ClearHeaders();

     

    Response.ClearContent();

     

    Response.Clear();

     

    Response.ContentType =

     

    "application/octet-stream";

     

     

    Response.AddHeader(

     

    "Content-Length", buffer.Length.ToString());

     

     

    Response.AddHeader(

     

    "Content-Disposition", "attachment; filename=" + file.Name);

     

     

    Response.BinaryWrite(buffer);

     

    }

     

    }




  2. Dobromir
    Admin
    Dobromir avatar
    1633 posts

    Posted 02 Jun 2011 Link to this post

    Hi Sandhya,

    I believe the following Live Demo and help article will help you solve this case:
    FileExplorer / Filter files and download
    Adding a custom button to the toolbar and an item to the tree context menu

    All the best,
    Dobromir
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top