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

Download files in async postback

4 Answers 674 Views
Grid
This is a migrated thread and some comments may be shown as answers.
S
Top achievements
Rank 1
S asked on 01 Jul 2009, 11:32 PM
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: 


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?

4 Answers, 1 is accepted

Sort by
0
BaiH
Top achievements
Rank 1
answered on 07 Jul 2009, 06:28 AM
I think you are missing the fact that actually xHttpRequest object cannot handle file streaming. So you must disable the Ajax before hitting the server for the download. You can check this article for a possible implementation.

--BH


0
Accepted
Princy
Top achievements
Rank 2
answered on 07 Jul 2009, 07:08 AM
Hello,

Refer to the following help document which you may find helpful to achieve your requirement:
AJAX And File Upload

Also check out the following forum link which discusses on a similar issue:
AJAX and File Download

Hope this helps...
-Princy.
0
S
Top achievements
Rank 1
answered on 07 Jul 2009, 02:32 PM
Thanks BH.
I had not seen that link.
0
S
Top achievements
Rank 1
answered on 07 Jul 2009, 02:40 PM
Thanks Princy. I found that link and implemented it....
Tags
Grid
Asked by
S
Top achievements
Rank 1
Answers by
BaiH
Top achievements
Rank 1
Princy
Top achievements
Rank 2
S
Top achievements
Rank 1
Share this question
or