IntroductionIn this tips, I have Explore, how to open crystal report as PDF in asp.net inline of browser. Because when you are work with crystal report in web application, most the users would like to have the PDF format document other than any other formats. The Following code help to you, open crystal report as PDF in inline of the browser. Html <%@ Page Language="C#" AutoEventWireup="true" CodeFile="CROpenInLine.aspx.cs" Inherits="CROpenInLine" %>
<%@ Register Assembly="CrystalDecisions.Web, Version=11.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"
Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
<!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>The Crystatl Report open as PDF inline in ASP.NET</title></head><body><form id="form1" runat="server"><asp:Button ID="btnOpen" runat="server" Text="Open PDF" OnClick="btnOpen_Click" /><div><CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" /></div></form></body></html>In above html, I have added crystal report and a button. C# using System;using System.Data;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.HtmlControls;using CrystalDecisions.Enterprise;using CrystalDecisions.CrystalReports.Engine;public partial class CROpenInLine : System.Web.UI.Page
{protected void Page_Load(object sender, EventArgs e){}protected void btnOpen_Click(object sender, EventArgs e){ReportDocument report = new ReportDocument();report.Load("File Path");
report.SetDataSource("Data Source");// this is convert as pdf and open in inline of the broswerreport.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, False, "");}} In above code , the key line is report.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, False, ""); The report object has ExportToHttpResponse method will accept, the first argument as ExporeFormatType. Second parameter is current response object to write in to browser. third parameter is indicate is converted PDF is be attachment or not, if you are set as true , then will open with save dialog box and also you have to specify the filename of the PDF. I hope this is help to you all. |