Click here to Skip to main content
15,118,323 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I've created one crystal report in windows form and one crystalreportviewer. The following is my code.

//in form1.cs file
ExportOptions CrExportOptions;
DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
CrDiskFileDestinationOptions.DiskFileName = "c:\\";
CrExportOptions = cryRpt.ExportOptions;
 CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
 CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
 CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
 CrExportOptions.FormatOptions = CrFormatTypeOptions;

Above code is saving the file into pdf into specified path. I dont want to save a file I should get direct print preview and have a option to print.

As we do in web application using crystal report viewer clicking print and report will be opened in pdf and the click print.

I want the same function as we do in web application. I am writing code in C#.Net

Hope the above explaination will be understood clearly.
Updated 29-Sep-10 4:39am
#realJSOP 29-Sep-10 10:06am
Do you want us to write the code for you, or are you stuck on some as-yet unrevealed aspect of your code?

1 solution

You can export a crystal report to a memory pdf this way in ASP.Net:

MemoryStream oStream; // using System.IO
oStream = (MemoryStream)
Response.Buffer= true;
Response.ContentType = "application/pdf";

If you are using windows forms, you need to use the crystal report viewer control. Here is a tutorial on how to use that control:[^]
vinu.1111 4-Oct-10 0:44am
thank u very much.. but there's one problem how to write the above code in windows form.
in windows form responce.clear or any thing response is not supported. it showing missing directive or.
namespace. please can u write for windows form.
thanks u once again and i'll try this for aspx also.. but i need is for windows form..
[no name] 4-Oct-10 11:38am
I did not notice the windows forms part of the question. I updated the answer to a tutorial on using the CrystalReportViewer control
vinu.1111 13-Oct-10 0:26am
thanku very much but there's one problem.. i should pass the parameter to the report
how can i do this...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900