Export PDF from Crystal Report .NET using ASP.NET (1)

suicidal

Newcomer
Joined
Feb 5, 2004
Messages
1
I'm able to view the report, but when I click the button on the webpage that shows the report to export into a different format it gives me an error on Export. Any help would be great!

I keep getting the following error:

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 95: myExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
Line 96: myExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
Line 97:
Line 98: report.Export();
Line 99:

HERE IS MY CODE:


private void Page_Load(object sender, System.EventArgs e)
{
report = new MainProject.Reporting.crcustomerreport();

// Create connection
SqlConnection objConn = new SqlConnection(ConfigurationSettings.AppSettings"ConnectionString");
SqlCommand myCommand = new SqlCommand("getCustomersNoOwnerIDReturned", objConn);
myCommand.CommandType = CommandType.StoredProcedure;

SqlParameter parameterOwnerID2 = new SqlParameter("@OwnerID", SqlDbType.VarChar, 50);
parameterOwnerID2.Value = (string)Session"OwnersUserName";
myCommand.Parameters.Add(parameterOwnerID2);

SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand);

MainProject.Reporting.dscustomerreport ds = new MainProject.Reporting.dscustomerreport();
myAdapter.Fill(ds, "Customers");

report.SetDataSource(ds);

CrystalReportViewer1.DisplayGroupTree = false;
CrystalReportViewer1.DisplayToolbar = false;

CrystalReportViewer1.ReportSource= report;
}


private void btnExport_Click(object sender, System.EventArgs e)
{
ExportOptions myExportOptions;
DiskFileDestinationOptions myDiskFileDestinationOptions;

string myExportFile;
report = new MainProject.Reporting.crcustomerreport();
myExportFile = @"C:\temp\" + Session.SessionID.ToString() + ".pdf";

myDiskFileDestinationOptions = new DiskFileDestinationOptions();

myDiskFileDestinationOptions.DiskFileName = myExportFile;

myExportOptions = report.ExportOptions;

myExportOptions.DestinationOptions = myDiskFileDestinationOptions;
myExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
myExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;

report.Export();

Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.WriteFile(myExportFile);
Response.Flush();
Response.Close();

System.IO.File.Delete(myExportFile);

}

Can anyone tell me what I need to do to fix this problem. I'll need details, I'm new to Crystal Reports .NET.

Thanks,
Harold
 
I had the same problem but It's been so long ago I can't remember the whole explanation. Go to crystaldecisions and do a search for export pdf and you should find the article that gave me the code below.

Dim crReportDocument As New CRFreightInvoices
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldDefinition As ParameterFieldDefinition
Dim crParameterValues As ParameterValues
Dim crParameterDiscreteValue As ParameterDiscreteValue

Dim crtableLogoninfos As New TableLogOnInfos
Dim crtableLogoninfo As New TableLogOnInfo
Dim crConnectionInfo As New ConnectionInfo
Dim CrTables As Tables
Dim CrTable As Table
Dim TableCounter

With crConnectionInfo
.ServerName = "db01"
.DatabaseName = "db1"
.UserID = "sa"
.Password = "pssword"
End With

CrTables = crReportDocument.Database.Tables

For Each CrTable In CrTables
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
Next




crParameterFieldDefinitions = crReportDocument.DataDefinition.ParameterFields
crParameterFieldDefinition = crParameterFieldDefinitions.Item("InvoiceNo")
crParameterValues = crParameterFieldDefinition.CurrentValues

crParameterDiscreteValue = New ParameterDiscreteValue
crParameterDiscreteValue.Value = ddlinv.SelectedItem.Text '1st current value
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)


Dim ExportOpts As CrystalDecisions.Shared.ExportOptions
Dim diskopts As New CrystalDecisions.Shared.DiskFileDestinationOptions
Dim exFilePath As String

ExportOpts = crReportDocument.ExportOptions
ExportOpts.ExportFormatType = ExportOpts.ExportFormatType.PortableDocFormat
ExportOpts.ExportDestinationType = ExportOpts.ExportDestinationType.DiskFile
exFilePath = "c:\" & Session.SessionID & ".pdf"
diskopts.DiskFileName = exFilePath
ExportOpts.DestinationOptions = diskopts
crReportDocument.Export()
Response.Redirect("PageForm.aspx")
 
suicidal said:
I'm able to view the report, but when I click the button on the webpage that shows the report to export into a different format it gives me an error on Export. Any help would be great!

Can anyone tell me what I need to do to fix this problem. I'll need details, I'm new to Crystal Reports .NET.

Thanks,
Harold

i don't know how to fix your problem but this code works great for me
-----

MemoryStream oStream;

oStream = (MemoryStream) report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);

Response.Clear();
Response.Buffer= true;
Response.ContentType = "application/pdf";
Response.BinaryWrite(oStream.ToArray());
Response.End();

-----
 
I had the same problem but i was using visual c#.

What i did was register my crystal reports and then, i searched in the their site for crystal reports.net

there u have to download the modules and include them in your project. those modules r

Crystal_Database_Access2003.msm,
Crystal_Database_Access2003_enu.msm,
Crystal_Managed2003.msm,
Crystal_regwiz2003.msm.

in the module Crystal_regwiz2003.msm you have to include the key you got when you registered your crystal report.

to get the key, you can go to the menu help-->about

this should to the the trick....you should be able to export your reports :)
 
Back
Top