This is a migrated thread and some comments may be shown as answers.

Implimentation download custom button functionality in RAD File explorer

1 Answer 235 Views
FileExplorer
This is a migrated thread and some comments may be shown as answers.
sandhya
Top achievements
Rank 1
sandhya asked on 31 May 2011, 07:59 AM
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);

 

}

 

}




1 Answer, 1 is accepted

Sort by
0
Dobromir
Telerik team
answered on 02 Jun 2011, 03:14 PM
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.

Tags
FileExplorer
Asked by
sandhya
Top achievements
Rank 1
Answers by
Dobromir
Telerik team
Share this question
or