-----------------------------------------------------------
New Message on BDOTNET
-----------------------------------------------------------
From: GuitarMate
Message 1 in Discussion
Hi, I have a requirement like exporting the crystal report content to PDF format,
it is for an ASP.NET project with C# as code behind and sql server as backend. But the
error which i am getting is really carzy. It says Logon Failed. I tried both the
Exporting by saving to a file format and Memory stream, in both this ways i am getting
the same error. If you have any idea where i have gone worong please guide me. Also
i have given the read\write access permission for the "Temp" folder, to the ASP.NET
user account. I dont know where am i missing.. If you could help me it will be useful
for me. Please check out the attached Code behind c# file, and the error message down
below that. Actaully i am able to populate the dataset values into the Crystal
reports viewer control. I am also able to view the report properly. But only i am not
able to Export to PDF. Can you help me in fixing this problem, or if you have a very
simple example code for exporting to PDF please pass on. Or suggest me if i missed
some settings or things like that. thanks in advance Balu.P
************************************************************* using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Resources;
using System.IO; using CrystalDecisions.Web;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
using MyNsps.Internet.B2BPortal.Website.Admin.Reports; namespace
MyNsps.Internet.B2BPortal.Website.Admin
{
/// <summary>
/// Summary description for RptCustomerLoginsResult.
/// </summary>
public class RptCustomerLoginsResult : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button btnExport;
protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1;
public CustomerLoginLogs objCustomerLoginLogsReport = new CustomerLoginLogs();
DataSet dsCustomerLoginLogs = new DataSet("CustomerLoginLogs");
DataTable dtCustomerLoginLogs = new DataTable("CustomerLoginLogsDataTable");
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (!IsPostBack)
{
if (Session["ReportDataset"]!= null)
{
dtCustomerLoginLogs = (DataTable)Session["ReportDataset"];
dsCustomerLoginLogs.Tables.Add(dtCustomerLoginLogs.Copy());
GenerateReport();
} }
} public void GenerateReport()
{
// if (Session["ReportDataset"]!= null)
// {
objCustomerLoginLogsReport.SetDataSource(dsCustomerLoginLogs);
CrystalReportViewer1.ReportSource = objCustomerLoginLogsReport;
// set report source
CrystalReportViewer1.DataBind();
// }
} #region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnExport.Click += new System.EventHandler(this.btnExport_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void btnExport_Click(object sender, System.EventArgs e)
{
// MemoryStream oStream; // using System.IO
// oStream =
(MemoryStream)objCustomerLoginLogsReport.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
// Response.Clear();
// Response.Buffer= true;
// Response.ContentType = "application/pdf";
// Response.BinaryWrite(oStream.ToArray());
// Response.End(); ExportReport(objCustomerLoginLogsReport);
//objCustomerLoginLogsReport.Export();
} private void ExportReport(ReportDocument rpt)
{ // prepare to export
ExportOptions crExportOptions;
DiskFileDestinationOptions crDiskFileDestinationOptions;
string Fname= @"C:\TEMP\" +Session.SessionID.ToString() + ".pdf";
//insure ASPNET account have permissions to write files on C:\TEMP
crDiskFileDestinationOptions = new DiskFileDestinationOptions();
crDiskFileDestinationOptions.DiskFileName= Fname; crExportOptions =
rpt.ExportOptions;
crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
rpt.Export();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.WriteFile(Fname);
Response.Flush();
Response.Close(); //delete the exported file from disk
//System.IO.File.Delete(Fname);
} }
}
****************************************************** Error
******************************************************* Server Error in '/MyNsps'
Application. Logon failed. Description: An unhandled exception occurred during the
execution of the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: CrystalDecisions.CrystalReports.Engine.LogOnException: Logon failed.
Source Error:
Line 130: Line 131: Line 132: rpt.Export();
Line 133: Response.ClearContent(); Line 134:
Response.ClearHeaders();
Source File: c:\inetpub\wwwroot\MyNsps\rptcustomerloginsresult.aspx.cs Line: 132
Stack Trace:
[LogOnException: Logon failed.] .F(String , EngineExceptionErrorID )
.A(Int16 , Int32 ) .@(Int16 )
CrystalDecisions.CrystalReports.Engine.FormatEngine.Export(ExportRequestContext
reqContext) CrystalDecisions.CrystalReports.Engine.FormatEngine.Export()
CrystalDecisions.CrystalReports.Engine.ReportDocument.Export()
AlBatha.Internet.B2BPortal.Website.Admin.RptCustomerLoginsResult.ExportReport(ReportDocument
rpt) in c:\inetpub\wwwroot\MyNsps\rptcustomerloginsresult.aspx.cs:132
AlBatha.Internet.B2BPortal.Website.Admin.RptCustomerLoginsResult.btnExport_Click(Object
sender, EventArgs e) in c:\inetpub\wwwroot\MyNsps\rptcustomerloginsresult.aspx.cs:106
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you received
this message by mistake, please click the "Remove" link below. On the pre-addressed
e-mail message that opens, simply click "Send". Your e-mail address will be deleted
from this group's mailing list.
mailto:[EMAIL PROTECTED]