Print Crystal Report Without Viewer

  • Thread starter Thread starter Andrew Hayes
  • Start date Start date
A

Andrew Hayes

Using VS 2005, CR10, writing in C#.NET.

How do I open a report, change the dataset, and export the results to PDF
from code without any user interaction?
 
Hi,


Andrew Hayes said:
Using VS 2005, CR10, writing in C#.NET.

How do I open a report, change the dataset, and export the results to PDF
from code without any user interaction?

Just doing it :)

Instantiate the report, get the dataset, use ReportDocument.SetDataSource(
theDataSet )

Then use ReportToDisk to export it in pdf format


and you are ready :)

Let me know if you need code, but it;s very straighforward.
 
i have this code :

ReportDocument reportDocument1 = new ReportDocument();
reportDocument1.Load(Request.PhysicalApplicationPath +
"\\reports\\VBilancio.rpt");

reportDocument1.SetDataSource(dsBil);
string TargetFileName;
FileStream fs;
long FileSize;
ExportOptions oExO;
DiskFileDestinationOptions oExDo = new DiskFileDestinationOptions();
TargetFileName = Request.PhysicalApplicationPath + "\\Export\\" +
Session.SessionID + "bilancio.pdf";

oExDo.DiskFileName = TargetFileName;
oExO = reportDocument1.ExportOptions;
oExO.ExportDestinationType = ExportDestinationType.DiskFile;
oExO.ExportFormatType = ExportFormatType.PortableDocFormat;
oExO.DestinationOptions = oExDo;

reportDocument1.PrintOptions.PaperOrientation=PaperOrientation.Landscape;
reportDocument1.SetParameterValue("data_fine",data2);
reportDocument1.SetParameterValue("data_ini",data1);
reportDocument1.Export();
reportDocument1.Close();

Response.Clear();
Response.Buffer = true;
Response.AddHeader("Content-Type", "application/pdf");
Response.AddHeader("Content-Disposition",
"attachment;filename=ReportBilancio.pdf;");
fs = new FileStream(TargetFileName, FileMode.Open);
FileSize = fs.Length;

byte[] bBuffer = new byte[(int)(FileSize)];
fs.Read(bBuffer, 0, (int)(FileSize));

fs.Close();
Response.BinaryWrite(bBuffer);
Response.Flush();
Response.Close();

this code was ok with visual studio .net 2003 but with visual studio 2005
dont'work and appears an error similar to this :

error in the motor of the query

the permissions are ok and the the virtual directory is ok

what can he be?

thanks a lot
Micky
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top