Hi All,
I have a radgrid with a gridbuttoncolumn that l use to let users download excel files.
Its straight-forward:
<telerik:GridButtonColumn HeaderText="Download" Text="Get Report" |
UniqueName="dldReportColumn" CommandName="PullReport"> |
</telerik:GridButtonColumn> |
On the click event, I am trying to send the generated file, but its giving a wierd error:
The closest scenario I have found here is:
http://www.telerik.com/community/forums/aspnet-ajax/grid/target-for-gridbuttoncolumn.aspx
http://www.telerik.com/community/forums/aspnet-ajax/grid/target-for-gridbuttoncolumn.aspx
But thats not the solution I want. In my earlier project, we used to be able to send the file directly to the user using Response.Write() and IE would open a dialog asking users to Open, Save or Cancel the file...
How do I achieve the file download ability using teleric:GridButtonColumn?
My code for the command handler is:
Protected Sub BatchGrid_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles BatchGrid.ItemCommand |
If e.CommandName = "PullReport" Then |
Dim chosen As GridDataItem = DirectCast(e.Item, GridDataItem) |
Dim folder As String = chosen("folder").Text |
Dim file As String = chosen("file").Text |
'The first task is to ensure that the file exists. |
Dim fullPath As String = Path.Combine(folder, file) |
Dim fi As FileInfo = New FileInfo(fullPath) |
If fi.Exists() Then |
Dim id As String = chosen("BatchID").Text |
Response.ClearContent() |
Response.AddHeader("Content-disposition", "attachment; filename=" & file) |
Response.AddHeader("Content-Length", fi.Length) |
Response.ContentType = "application/octet-stream" |
Response.TransmitFile(fullPath) |
Response.Flush() |
Response.End() |
End If |
End If |
End Sub |
This is a common scenario ... how do I get the download functionality?