Below is the sample code (I’M generating reports programmatically
from JSON data)
public static void Export(Telerik.Reporting.ReportBook reportToExport, string type, string cType)
{
var reportProcessor = new
Telerik.Reporting.Processing.ReportProcessor();
var instanceReportSource = new
Telerik.Reporting.InstanceReportSource();
instanceReportSource.ReportDocument
= reportToExport;
if (type.ToLower().Equals("print"))
{
//
Obtain the settings of the default printer.
PrinterSettings printerSettings
= new
PrinterSettings();
//printerSettings.PrinterName
= " HP Deskjet 3510 series";
//
Print the report using the printer settings.
reportProcessor.PrintReport(reportToExport, printerSettings);
}
else
{
Telerik.Reporting.Processing.RenderingResult result =
reportProcessor.RenderReport(type,
instanceReportSource, null);
string fileName = "Viewr_" + cType + "_report." + result.Extension;
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = result.MimeType;
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Private);
HttpContext.Current.Response.Expires
= -1;
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.AddHeader("Content-Disposition",
string.Format("{0};FileName=\"{1}\"",
"attachment",
fileName));
HttpContext.Current.Response.BinaryWrite(result.DocumentBytes);
HttpContext.Current.Response.End();
}
}
from JSON data)
public static void Export(Telerik.Reporting.ReportBook reportToExport, string type, string cType)
{
var reportProcessor = new
Telerik.Reporting.Processing.ReportProcessor();
var instanceReportSource = new
Telerik.Reporting.InstanceReportSource();
instanceReportSource.ReportDocument
= reportToExport;
if (type.ToLower().Equals("print"))
{
//
Obtain the settings of the default printer.
PrinterSettings printerSettings
= new
PrinterSettings();
//printerSettings.PrinterName
= " HP Deskjet 3510 series";
//
Print the report using the printer settings.
reportProcessor.PrintReport(reportToExport, printerSettings);
}
else
{
Telerik.Reporting.Processing.RenderingResult result =
reportProcessor.RenderReport(type,
instanceReportSource, null);
string fileName = "Viewr_" + cType + "_report." + result.Extension;
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = result.MimeType;
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Private);
HttpContext.Current.Response.Expires
= -1;
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.AddHeader("Content-Disposition",
string.Format("{0};FileName=\"{1}\"",
"attachment",
fileName));
HttpContext.Current.Response.BinaryWrite(result.DocumentBytes);
HttpContext.Current.Response.End();
}
}