I have created my RadGrid and have exporting to Excel working well when the user clicks on an export button in their browser.
I have also used the code below to make it so that the Excel file can be saved programatically without bringing up the file save dialog. This code is also working well.
Now, what I need to do is automate and schedule this process: the creation of the grid, the firing off the export to Excel function, and saving that exported Excel file to a directory on the web server. In order to accomplish that, I created a windows application that would sit on the same web server and would call the web page that contains the grid. That works fine.
The problem that I have is that I don't know how to fire the GridExporting event without using some client side interaction or client-side javascript. I am using an HttpWebRequest in my windows application to make the web request, but HttpWebRequest doesn't support javascript, so it can't trigger the GridExporting event.
Is there anyway to call the GridExporting event from the server-side and not the client-side? If so, during what event should I make that call from and what does that call look like?
I know that as an alternative, I could totally skip using RadGrid, and for these automated exporting calls, simply take my raw data and create an excel sheet programatically using NPOI or some other tool and save it. The issue is that I will still be using RadGrid on the web, and I have built the web application so that the data in the grid can be customized significantly by my users (through sorting, grouping, hiding columns, etc), and I really want the programatically created Excel file to provide the same data, in as close to the same format, as if the user used the RadGrid's export to Excel function on the website.
It seems that I am very close to making that happen, if I can just figure out how to trigger the export function on the server-side.
Thanks in advance for your help!
This is the code that I am using to save the Excel file programatically without bringing up the file save dialog. This code is working great.
I have also used the code below to make it so that the Excel file can be saved programatically without bringing up the file save dialog. This code is also working well.
Now, what I need to do is automate and schedule this process: the creation of the grid, the firing off the export to Excel function, and saving that exported Excel file to a directory on the web server. In order to accomplish that, I created a windows application that would sit on the same web server and would call the web page that contains the grid. That works fine.
The problem that I have is that I don't know how to fire the GridExporting event without using some client side interaction or client-side javascript. I am using an HttpWebRequest in my windows application to make the web request, but HttpWebRequest doesn't support javascript, so it can't trigger the GridExporting event.
Is there anyway to call the GridExporting event from the server-side and not the client-side? If so, during what event should I make that call from and what does that call look like?
I know that as an alternative, I could totally skip using RadGrid, and for these automated exporting calls, simply take my raw data and create an excel sheet programatically using NPOI or some other tool and save it. The issue is that I will still be using RadGrid on the web, and I have built the web application so that the data in the grid can be customized significantly by my users (through sorting, grouping, hiding columns, etc), and I really want the programatically created Excel file to provide the same data, in as close to the same format, as if the user used the RadGrid's export to Excel function on the website.
It seems that I am very close to making that happen, if I can just figure out how to trigger the export function on the server-side.
Thanks in advance for your help!
This is the code that I am using to save the Excel file programatically without bringing up the file save dialog. This code is working great.
Protected
Sub
RadGrid1_GridExporting(sender
As
Object
, e
As
Telerik.Web.UI.GridExportingArgs)
Handles
myGrid.GridExporting
'This handler saves the file DIRECTLY to the server directory without showing the save as dialog
path = Server.MapPath(
"~/MyFile.xls"
)
Dim
fs
As
FileStream
fs = File.Create(path)
Dim
info
As
Byte
()
info = System.Text.Encoding.
Default
.GetBytes(e.ExportOutput)
fs.Write(info, 0, info.Length)
fs.Close()
Response.Redirect(Request.Url.ToString(),
False
)
End
Sub