Click here to Skip to main content
14,236,507 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi,

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

//in form1.cs file
try
{
ExportOptions CrExportOptions;
DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
CrDiskFileDestinationOptions.DiskFileName = "c:\\csharp.net-informations.pdf";
CrExportOptions = cryRpt.ExportOptions;
{
 CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
 CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
 CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
 CrExportOptions.FormatOptions = CrFormatTypeOptions;
}
 cryRpt.Export();
}

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.
Posted
Updated 29-Sep-10 3:39am
v2
Comments
#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

Rate this:
Please Sign up or sign in to vote.

Solution 2

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

MemoryStream oStream; // using System.IO
oStream = (MemoryStream)
report.ExportToStream(
CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
Response.Clear();
Response.Buffer= true;
Response.ContentType = "application/pdf";
Response.BinaryWrite(oStream.ToArray());
Response.End();


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:

http://www.aspfree.com/c/a/.NET/Using-CrystalReportViewer-to-Display-Crystal-Reports-in-Net[^]
   
v2
Comments
vinu.1111 4-Oct-10 0:44am
   
GOOD MORNING....
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..
William Jordan 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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100