Solved

ReportViewer render as PDF

Posted on 2010-09-22
8
2,130 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

27 Experts available now in Live!

Get 1:1 Help Now