New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Export PDF File from RadSpreadsheet to the Server Directory

Description

How to export a spreadsheet from RadSpreadsheet into the server directory, not to the client.

Solution

On the Client-side attach an event to the button. In OnClientClicking, the current state of the SpreadSheet is stored in a hidden field as a stringified JSON.

function OnClientClicking(sender, args) {
    var spr = $find("<%= RadSpreadsheet1.ClientID %>"); 
    var hf = $get("<%= HiddenField1.ClientID %>");
    var kendoWidget = spr.get_kendoWidget();
    var json = kendoWidget.toJSON();
    hf.value = JSON.stringify(json);
}

In the code behind, create an AJAX workbook from the hidden field value and convert it to a Telerik Document Processing Library workbook:

Telerik.Web.Spreadsheet.Workbook workbook = Telerik.Web.Spreadsheet.Workbook.FromJson(HiddenField1.Value);
Telerik.Windows.Documents.Spreadsheet.Model.Workbook document = workbook.ToDocument();

Saving a file using Telerik Document Processing Libraries which allows you to create, import, modify, and export documents without relying on external dependencies like Adobe Acrobat or Microsoft Office.

//Import/Load and Export/Save RadSpreadProcessing Workbook
byte[] bytesFromWorkbook = provider.Export(document);
var path = Server.MapPath("~/App_Data/MyFile.pdf"); 
File.WriteAllBytes(path, bytesFromWorkbook);
In this article