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

Downloading from a grid

1 Answer 54 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jed Fletcher
Top achievements
Rank 1
Jed Fletcher asked on 28 Apr 2010, 12:35 PM
I have got a button on the grid that when clicked sets a viewstate item to a file.
Now when i try use the response it gives me a error.
Now i have seen you can do it by
RadAjaxPanel1.ResponseScripts.Add(String.Format(@"window.location.href = ""{0}"";", http://yoursite.com/Your_File));

But how would one use this to do

response.binarywrite(byte[])

Please any help will be much appreciated. If this is in the incorrect section plese relocate.
Thanks

1 Answer, 1 is accepted

Sort by
0
Accepted
Veli
Telerik team
answered on 03 May 2010, 09:30 AM
Hello Jed,

window.location.href is used for cases when you have your file stored in a directory on the web server. In your case, as you say, you have it loaded in memory on postback. So, you can do:

//attachment is the byte[] contaning the file data
//attachmentFileNameis the name of the file
 
CurrentHttpResponse.Clear();
CurrentHttpResponse.ContentType = "application/octet-stream";
CurrentHttpResponse.AddHeader("content-disposition", "attachment; filename=" + attachmentFileName);
CurrentHttpResponse.BinaryWrite(attachment);
CurrentHttpResponse.End();

Also, note that saving your files in the ViewState may not be very efficient. After all, the ViewState is serialized to the response page. It's like downloading your attachment on every page refresh.

Regards,
Veli
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Jed Fletcher
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or