using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WinFormsReportExport
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnExportReport_Click(object sender, EventArgs e)
        {
            var reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();

            // set any deviceInfo settings if necessary
            var deviceInfo = new System.Collections.Hashtable();

            var instanceReportSource = new Telerik.Reporting.InstanceReportSource();

            instanceReportSource.ReportDocument = new ReportLibrary.Report1();

            Telerik.Reporting.Processing.RenderingResult result =
                reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo);

            string fileName = result.DocumentName + "." + result.Extension;
            string path = System.IO.Path.GetTempPath();
            string filePath = System.IO.Path.Combine(path, fileName);
            System.Diagnostics.Process prc = new System.Diagnostics.Process();
            string windir = Environment.GetEnvironmentVariable("WINDIR");
            prc.StartInfo.FileName = windir + @"\explorer.exe";
            prc.StartInfo.Arguments = path;
            prc.Start();
            using (System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Create))
            {
                fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
            }
        }
    }
}
