Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2432
  • Last Modified:

ReportViewer render as PDF

Ive got a report working great using a ReportViewer in, however every load I convert the HTML report into a PDF.

Is it possible instead of loading the ReportViewer up in the HTML view, outputting the PDF straight away?

I know I have to do:-
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment; filename=Test.pdf)

However I have no idea how to set the ReportViewer to output PDF straight away.

Any ideas on how I can do this, any code examples would be appriciated.

Thank you
  • 4
  • 4
1 Solution
''''''''''''''''''''   try this one on your *.aspx.vb

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 End Sub

Protected Sub Page_LoadComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadComplete
Dim fl As String = "c:\inetpub\wwwroot\samplereport.pdf"
Dim virtualDir = "http://localhost/samplereport.pdf"
Dim rds As ReportDataSource = New ReportDataSource("yourDataSetName", ObjectDataSource1)
        Dim b As Byte()
        b = ReportViewer1.LocalReport.Render("PDF", Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)

        If File.Exists(fl) = True Then
        End If

        Dim fs As New FileStream(fl, FileMode.Create)
        fs.Write(b, 0, b.Length)

        If File.Exists(fl) = True Then
              response.redirect(virtualDir )
             'or use a httphandler instead of just redirecting
        End If
 End Sub
tonelm54Author Commented:
Looks good, but when it runs:-
          b = ReportViewer1.LocalReport.Render("PDF", Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)

I get "An error occurred during local report processing."
tonelm54Author Commented:
Without the code, it does render the HTML report correctly.
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

can you tell me more about the error? what exactly is the description?
tonelm54Author Commented:
The message Im getting is:-

Microsoft.ReportingServices.ReportProcessing.ProcessingAbortedException: An error has occurred during report processing. ---> Microsoft.ReportingServices.ReportProcessing.ReportProcessingException: DataSet1

An error occurred during local report processing.
tonelm54Author Commented:
My code is attached
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication18.WebForm1" %>

<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">

    <asp:ScriptManager ID="ScriptManager1" runat="server">
            <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
        <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" 
            Font-Size="8pt" InteractiveDeviceInfos="(Collection)" 
            WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt">
            <LocalReport ReportPath="Report1.rdlc">
                    <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="DataSet1" />


Open in new window

'can you check please if DataSet1 is being  set to rds as report datasource on Sub Page_LoadComplete

'it shoul be like this below
Dim rds As ReportDataSource = New ReportDataSource("DataSet1", ObjectDataSource1)
sorry I forgot to add you need to add

Imports System.IO

on the top of your aspx.vb
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now