This is a migrated thread and some comments may be shown as answers.

Export Programmatically using external button

1 Answer 124 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 10 Jun 2014, 09:20 AM
Dear All,

I've been trying to search for mechanisms to call exporting of telerik report viewer externally using button.

I came across the following code but do not have much clue about how to pass in the input "reportToExport"? What exactly is the Assembly Qualified Name of the report? and where can I find it? Much appreciated any help. Thanks

void ExportToPDF(string reportToExport)
{
    var reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();
    var typeReportSource = new Telerik.Reporting.TypeReportSource();

    // reportToExport is the Assembly Qualified Name of the report
    typeReportSource.TypeName = reportToExport;

    var result = reportProcessor.RenderReport("PDF", typeReportSource, null);

    this.Response.Clear();
    this.Response.ContentType = result.MimeType;
    this.Response.Cache.SetCacheability(HttpCacheability.Private);
    this.Response.Expires = -1;
    this.Response.Buffer = true;

    /* Uncomment to handle the file as attachment
     Response.AddHeader("Content-Disposition",
                    string.Format("{0};FileName=\"{1}\"",
                                    "attachment",
                                    fileName));
     */

    this.Response.BinaryWrite(result.DocumentBytes);
    this.Response.End();
}

1 Answer, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 12 Jun 2014, 02:44 PM
Hi Tim,

The referenced code snippets assumes that you have created your report in the Visual Studio Report Designer. In this case you can get the Type.AssemblyQualifiedName as shown in the following code snippet:

void ExportToPDF()
{
    var reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();
    var typeReportSource = new Telerik.Reporting.TypeReportSource();
 
    // reportToExport is the Assembly Qualified Name of the report
    typeReportSource.TypeName = typeof(ReportCatalog).AssemblyQualifiedName;
 
    var result = reportProcessor.RenderReport("PDF", typeReportSource, null);
 
    this.Response.Clear();
    this.Response.ContentType = result.MimeType;
    this.Response.Cache.SetCacheability(HttpCacheability.Private);
    this.Response.Expires = -1;
    this.Response.Buffer = true;
 
    /* Uncomment to handle the file as attachment
     Response.AddHeader("Content-Disposition",
                    string.Format("{0};FileName=\"{1}\"",
                                    "attachment",
                                    fileName));
     */
 
    this.Response.BinaryWrite(result.DocumentBytes);
    this.Response.End();
}

In case you have used the Standalone Report Designer to create your report definitions you have to use UriReportSource.

Regards,
Peter
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
General Discussions
Asked by
Tim
Top achievements
Rank 1
Answers by
Peter
Telerik team
Share this question
or