How to set default file name for export from CrystalReportViewer in ASP.Net

I have had nice discussion about a new Crystal Reports based web-site today. And everything seems to be fine… Except users want to see a proper default name for the exported files…

Environment:

  • Crystal Reports 2008 engine
  • IIS 7
  • ASP.Net 3.0 page with CrystalReportViewer (CRV) being used to show report passed by parameter

When trying export as PDF (just an example), CRV defaults the name of the file to CrystalReportViewer1.pdf.
Not very nice since associated RPT name is MyVeryOwnReport.rpt and I have many other which I would expect export file at least inherit.

One would expect that Viewer would have a property allowing specify default export name. Not so fast… there is no such thing today exists.

After some head scratching and research, it just happen that Default Export File Name is actually based of the ID property value of the CRV which is still named as CrystalReportViewer1.

Options?

  1. Rename ID value of the control as something else. Still, if we use just one page and load reports dynamically, then it would not help much.
    // ReportPreview.aspx file
    <CR:CrystalReportViewer ID="MyVeryOwnExportFile" />
  2. Another option is to populate Default Export file name in the code
    // ReportPreview.aspx.cs file
    protected void Page_Init(object sender, EventArgs e)
    {
         ...
        // Load report here
        ...
        CrystalReportViewer1.ID = "MyVeryOwnExportFile";
    }

    It is important to have it set before any code would use it to manipulate a page view state and create references.

  3. Trying manually set export options for the Report instance, would not help much unfortunately since viewer would disregard it.
  4. Off course there is always an option of coding export functionality yourself and bypass built-in logic…

This concludes another Crystal Reports dance session.

This entry was posted in Crystal Reports and tagged , , , , . Bookmark the permalink.

3 thoughts on “How to set default file name for export from CrystalReportViewer in ASP.Net”

  1. nomex says:

    Thanks because in ASP it’s a very difficult.

  2. Jana says:

    Hi Thanks Its use full, I need one help please, suppose I want to concat a text box value with file name how to do that.

  3. Karthika Kalaivanan says:

    Thank You For reply. Its Working.

Leave a Reply

  • About

    From being a junior developer all the way to Development Manager position, I was always interested in new technologies. Passionate speaker, IT junky, developer, architect, team lead, and development manager - many hats, one goal - making software better and closer to people’s needs. For the most part I am using my blog as a scratch pad, writing small articles on things which I came across, was asked about more then once, and which would otherwise require additional research again and again.

    View Serguei Dosyukov's profile on LinkedIn
  • Testimonials

    I’m a huge fan of this theme. I’ve got more than 90,000 pictures in my gallery3 running on a Ubuntu...

    Jklobo

    I've been using this [theme] since the start. It is by far the most attractive, feature packed and stable of...

    Rhyull

    The greydragon theme is fantastic. It’s clean, stable and feature rich. It took me a while to decide to move...

    Ed

    more...

  • Categories