Solved

ReportViewer render as PDF

Posted on 2010-09-22
8
2,202 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

688 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