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

Programmatically set "NoHeader" ?

3 Answers 125 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 15 Oct 2013, 03:15 PM

We have created a report and are using the “Export” feature provided by the Report viewer.  All of the options are working satisfactorily except for the CSV option.  The CSV option is working as documented, but we really want to apply the “NoHeader” and “NoStaticText” options that have been documented.   The problem is that these go into the application config file.  Our report generator is part of an MMC snapin.   We do not have a configuration file to add these customizations to. All the documentation I have seen so far points to ReportProcessor.RenderReport() to programmatically modify the export behavior.  The examples around using this are not very helpful.  I do not see how to tie this into the “Export” button on the Report viewer.  I have found no events that are generated when a user chooses an export option.  I also want to use the provided UI for gathering the destination, and also use the provided “write to file” functionality.   The examples of RenderReport all seem to use a default location and provide their own write code.   

 

Is there a way to programmatically set the “NoHeader” and “NoStaticText” parameters for the CSV option without using RenderReport?   If the answer is no, can you point me to some documentation/examples of how to use RenderReport when a user selects an export option from the Export button?

 

Thanks.

Dave

3 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 17 Oct 2013, 12:25 PM
Hi Dave,

Do you use the Windows Forms Report Viewer? If this is the case you can utilize its Export event as shown in the following code snippet:
public partial class MainForm : Form
{
    public MainForm()
    {
        InitializeComponent();
        this.reportViewer1.Export += ReportViewer1Export;
    }
 
    void ReportViewer1Export(object sender, ReportViewer.WinForms.ExportEventArgs args)
    {
        switch(args.Format)
        {
            case "CSV":
                args.DeviceInfo.Add("NoHeader", true);
                args.DeviceInfo.Add("NoStaticText", true);
                break;
        }
    }
 
    void MainForm_Load(object sender, System.EventArgs e)
    {
        this.reportViewer1.RefreshReport();
    }
}

Just to note that this code will only work with versions Q3 2013 and newer.

Regards,
Peter
Telerik

Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.

0
David
Top achievements
Rank 1
answered on 18 Oct 2013, 06:31 PM

Peter,

Thank you for the sample, however when I started to implement it I ran into a problem.  Reading your comment “Just to note that this code will only work with versions Q3 2013 and newer”, I downloaded the latest version and started to work on my issue.  I then realized that I can’t use Q3 2013 or later, it requires .NET 4.0.  We use Telerik Reporting in a MMC snapin.  MMC snapins can only be built with .NET 3.5 or earlier.   Looking at the release notes, it looks like the latest kit I can use is 7.0.13.426 (April 26).  Will this solution work with that version?  If not, is there a way to accomplish what I want to do in 7.0.13.426?

 

Thanks,

Dave

0
Peter
Telerik team
answered on 21 Oct 2013, 11:29 AM
Hi Dave,

Another option that works with 7.0.13.426 is to cancel the report viewer rendering and render the report manually as shown in the following code snippet:

public MainForm()
{
    InitializeComponent();
    this.reportViewer1.Export += ReportViewer1Export;
}
 
void ReportViewer1Export(object sender, ReportViewer.WinForms.ExportEventArgs args)
{
    switch (args.Format)
    {
        case "CSV":
            args.Cancel = true;
 
            //Dummy code
            //if required you can render the report in different thread
            var reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();
            var deviceInfo = new System.Collections.Hashtable();
            deviceInfo.Add("NoHeader", true);
            deviceInfo.Add("NoStaticText", true);
            var rs = this.reportViewer1.ReportSource;
            var result = reportProcessor.RenderReport("CSV", rs, deviceInfo);
            //handle the resulted report according to your needs
 
            break;
    }
}

Regards,
Peter
Telerik

Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.

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