Skip to Content

How can you add your own print and export buttons to the CR viewer toolbar?

I posted a previous question that was asking how to get around the Information Bar in IE7 when you export and print. Unfortunately the CR viewer file download code gets blocked by IE7 because the buttons don't directly download the file. However, I have been able to get a regular button that calls the following code and streams the file to the client and IE7 does not block it.

Sub PrintPDF(sender As Object, e As System.EventArgs)

	Dim crReportDocument as ReportDocument
	Dim crExportOptions as ExportOptions
	Dim crDiskFileDestinationOptions as DiskFileDestinationOptions
	Dim Fname as string
	
	CrReportDocument = New ReportDocument()
	CrReportDocument.Load(Server.MapPath("estactionlist.rpt"))
	
	Fname = Server.MapPath("./") & Session.SessionID.ToString & ".pdf"
	CrDiskFileDestinationOptions = New DiskFileDestinationOptions()
	CrDiskFileDestinationOptions.DiskFileName = FName
	CrExportOptions = crReportDocument.ExportOptions
	With crExportOptions
		.DestinationOptions = CrDiskFileDestinationOptions
		.ExportDestinationType = ExportDestinationType.DiskFile
		.ExportFormatType = ExportFormatType.PortableDocFormat
	End With
	
	CrReportDocument.Export()
	
	Response.ClearContent()
	Response.ClearHeaders()
                Response.AddHeader("content-disposition", "attachment;filename=test.pdf")
                Response.ContentType = "application/pdf"
                Response.Charset = ""
                Response.WriteFile(Fname)
                Response.Flush()
	Response.Close()
	
	System.IO.File.Delete(Fname)

End Sub

So here are my questions?

1. Is it possible to add a custom print control/icon to the CR viewer toolbar?

2. If one is not possible, then is it possible to override the CR viewer print and export buttons with your own subroutines like the one above?

I just want my page to look nice and hate to have print and export buttons outside of my CR viewer.

Thanks,

Kevin

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    Posted on Jul 25, 2008 at 07:52 PM

    It might be possible to replace the buttons in a windows app since you can retrieve the toolbar as a toolbar object in the winform viewer ( ToolStrip toolBar = (ToolStrip) crystalReportViewer1.Controls[3]; ) however with a web app, it's a lot more difficult.

    The problem is that that you need to parse the Request string to try and figure out if the print / export button was clicked. The code below makes the print button disappear if you click it, so you should be able to modify it to call your custom printing / exporting code instead (You have to do this check in a postback)

            Dim I As Integer = 0
            If Request.Form.AllKeys.Length > 0 Then
    
                For I = 0 To Request.Form.AllKeys.Length - 1
                    Response.Write(Request.Form.Keys(I).ToString & "<BR>")
                    If Request.Form.Keys(I).ToString = "CrystalReportViewer2:_ctl2:_ctl2.x" Then
                        CrystalReportViewer2.HasPrintButton = False
                    End If
                Next
      
           End If 
    

    Shawn

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.