Solved

ReportViewer render as PDF

Posted on 2010-09-22
8
2,144 Views
Last Modified: 2012-08-13
Ive got a report working great using a ReportViewer in ASP.net, 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
0
Comment
Question by:tonelm54
  • 4
  • 4
8 Comments
 
LVL 3

Expert Comment

by:_bmendoza
ID: 33737960
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''   try this one on your *.aspx.vb
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ReportViewer1.LocalReport.Refresh()
 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)
        ReportViewer1.LocalReport.DataSources.Clear()
        ReportViewer1.LocalReport.DataSources.Add(rds)
        Dim b As Byte()
        b = ReportViewer1.LocalReport.Render("PDF", Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)


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

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

        If File.Exists(fl) = True Then
              response.redirect(virtualDir )
             'or use a httphandler instead of just redirecting
        End If
 End Sub
0
 

Author Comment

by:tonelm54
ID: 33738266
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."
0
 

Author Comment

by:tonelm54
ID: 33738274
Without the code, it does render the HTML report correctly.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 3

Expert Comment

by:_bmendoza
ID: 33739398
can you tell me more about the error? what exactly is the description?
0
 

Author Comment

by:tonelm54
ID: 33746686
The message Im getting is:-

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

Message
An error occurred during local report processing.
0
 

Author Comment

by:tonelm54
ID: 33746693
My asp.net code is attached
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication18.WebForm1" %>

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">

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

    </form>
</body>
</html>

Open in new window

0
 
LVL 3

Expert Comment

by:_bmendoza
ID: 33748143
'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)
0
 
LVL 3

Accepted Solution

by:
_bmendoza earned 500 total points
ID: 33748203
sorry I forgot to add you need to add

Imports System.IO

on the top of your aspx.vb
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question