none
Customizing ReportViewer RRS feed

  • Question

  • Hello,
    I am using Microsoft.ReportViewer. I have quite a few export options(export as pdf, word, excel... etc.). However, I want to restrict this option to "ExportAsPDF" alone. How do I customize my ReportViewer control?

    I searched in the internet and found some sites suggesting me to customize the entire report toolbar. Is there any other simplified solution?

    Please help.

    Thanks!
    Rashmi
    Tuesday, July 28, 2009 5:48 AM

Answers

  • Hi,
      first set the ReportViewer.ShowExportButton property to FALSE and after that place on button on the form and call the following code on its click event:

    Private Sub lnkExpotToPDF_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkExpotToWord.Click
            Dim buffer As Byte(), f As String, fs As System.IO.FileStream
            f = System.IO.Path.GetTempFileName()
            System.IO.Path.ChangeExtension(f, "pdf")
            buffer = ReportViewer1.ServerReport.Render("HTML3.2", Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)

            fs = New System.IO.FileStream(f, System.IO.FileMode.Create)
            fs.Write(buffer, 0, buffer.Length)
            fs.Close()
            fs.Dispose()


            Response.ContentType = "Application/pdf"
            Response.WriteFile(f)
            Response.AddHeader("content-disposition", "attachment; filename=FileName.pdf")

            Response.End()
            System.IO.File.Delete(f)

        End Sub

    Aftab Ansari
    Tuesday, July 28, 2009 8:25 AM

All replies

  • Hi,
      first set the ReportViewer.ShowExportButton property to FALSE and after that place on button on the form and call the following code on its click event:

    Private Sub lnkExpotToPDF_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkExpotToWord.Click
            Dim buffer As Byte(), f As String, fs As System.IO.FileStream
            f = System.IO.Path.GetTempFileName()
            System.IO.Path.ChangeExtension(f, "pdf")
            buffer = ReportViewer1.ServerReport.Render("HTML3.2", Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)

            fs = New System.IO.FileStream(f, System.IO.FileMode.Create)
            fs.Write(buffer, 0, buffer.Length)
            fs.Close()
            fs.Dispose()


            Response.ContentType = "Application/pdf"
            Response.WriteFile(f)
            Response.AddHeader("content-disposition", "attachment; filename=FileName.pdf")

            Response.End()
            System.IO.File.Delete(f)

        End Sub

    Aftab Ansari
    Tuesday, July 28, 2009 8:25 AM
  • hi,

    i want that pdf file should be in proper format but, its not. :(

    and it should be in C# instead VB.NET

    any help????????????????

     

     

    Thursday, April 21, 2011 11:26 PM