I posted this originally on this thread Save to File but haven't gotten any replies for a few days, so maybe that thread isn't being looked at, so I'm reposting here.
I'm using RadControls for ASP.NET AJAX Q2 2012 SP2
I'm using the described method to export to excel file, and it seems to work if I'm exporting a single grid. However, In my case I have three grids and I need to export all three to seperate excel files, then continue to do some additional processing after the exports are completed.
When I attempt to export mutliple excel files one after the other, none of the exports work. NO errors, NO nothing, see code excerpts below.
In addition, is there any way to suppress the open/save dialog when writing the exported file to disk, other than
Response.Redirect(Request.Url.ToString())
The issue seems to be with exporting multiple grids back to back.
I've also tried firing the Export Command from codebehind, the grids ItemCommand runs, but GridExporting doesn't.
Dim GCI As Telerik.Web.UI.GridCommandItem = CType(Me.rgSummary.MasterTableView.GetItems(Telerik.Web.UI.GridItemType.CommandItem)(0), Telerik.Web.UI.GridCommandItem)
GCI.FireCommandEvent("EXPORTTOEXCEL", String.Empty)
Any help would be appreciated.
Protected Sub btnExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExport.Click
Me.rgSummary.Rebind()
Me.rgSummary.ExportSettings.FileName = "Fantastic_Invoice_Summary_" + Format(Now, "MM_dd_yyyy_hh_mm_tt")
Me.rgSummary.ExportSettings.OpenInNewWindow = False
Me.rgSummary.MasterTableView.ExportToExcel()
'If I exit sub here, I'll get the summary excel file.
Me.rgDetail.Rebind()
Me.rgDetail.ExportSettings.FileName = "Fantastic_Invoice_Detail_" + Format(Now, "MM_dd_yyyy_hh_mm_tt")
Me.rgDetail.ExportSettings.OpenInNewWindow = False
Me.rgDetail.MasterTableView.ExportToExcel()
'I get neither file if I don't exit after the summary export
Me.rgCommission.Rebind()
If Me.rgCommission.Items.Count <> 0 Then
Me.rgCommission.ExportSettings.FileName = "Fantastic_Invoice_Commission_" + Format(Now, "MM_dd_yyyy_hh_mm_tt")
Me.rgCommission.ExportSettings.OpenInNewWindow = False
Me.rgCommission.MasterTableView.ExportToExcel()
End If
'Additional processing below
end sub
Private Sub rgSummary_GridExporting(sender As Object, e As Telerik.Web.UI.GridExportingArgs) Handles rgSummary.GridExporting
Dim fs As System.IO.FileStream
Dim FileName As String = Server.MapPath("~/Temp/") + Me.rgSummary.ExportSettings.FileName + "." + Me.rgSummary.ExportSettings.Excel.FileExtension
fs = System.IO.File.Create(FileName)
'Dim output As Byte() = Encoding.GetEncoding(1252).GetBytes(e.ExportOutput)
Dim output As Byte() = System.Text.Encoding.Default.GetBytes(e.ExportOutput)
fs.Write(output, 0, output.Length)
fs.Close()
End Sub