Solved

ReportViewer render as PDF

Posted on 2010-09-22
8
2,113 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
 
LVL 3

Expert Comment

by:_bmendoza
ID: 33739398
can you tell me more about the error? what exactly is the description?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now