Showing posts with label examples. Show all posts
Showing posts with label examples. Show all posts

Wednesday, March 7, 2012

How do I export a report using c#?...

Hi there.
Can anyone tell me how to export a report to PDF using only c#? I have seen lots of examples of how to do it using asp.net but I am only interested in using c#.
Thanks in advance to anyone who can help me out!Hi
Try this code

CrystalReport1 cr = new CrystalReport1();
ExportOptions exportOpts = new ExportOptions();

DiskFileDestinationOptions diskOpts = ExportOptions.CreateDiskFileDestinationOptions();

// Set the export format.
exportOpts.ExportFormatType = ExportFormatType.WordForWindows;
exportOpts.ExportDestinationType =ExportDestinationType.DiskFile;

// Set the disk file options.
diskOpts.DiskFileName = "C:\\Documents and Settings\\ceeb\\Desktop\\111.doc";
exportOpts.ExportDestinationOptions = diskOpts;
cr.Export(exportOpts);

All the best
:thumb:|||Thanks for the help.

In the end i did it like this:

public void exportReport(String reportName, String exportName)
{
try
{
//Create a ReportDocument and load in the location of the report
ReportDocument report = new ReportDocument();

report.Load(reportName);

//Create a DiskFileDestinationOptions object so you can set where the
//pdf is written to
DiskFileDestinationOptions diskFileDestinationOptions = new DiskFileDestinationOptions();

//append a filename to the export path and set this file as the filename property for
//the DestinationOptions class
diskFileDestinationOptions.DiskFileName = exportName;

//set the required report ExportOptions properties
ExportOptions exportOptions = report.ExportOptions;
exportOptions.DestinationOptions = diskFileDestinationOptions;
exportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
exportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;

//Once the export options have been set for the report, the report can be exported. The Export command
//does not take any arguments

// Export the report
report.Export();
Console.WriteLine(reportName + " exported successfully as " + exportName);
}
catch (Exception e)
{
Console.WriteLine(e.Message.ToString());
}

}|||I am trying to do the same thing, the only issue is , I either want to pass a data set (only a few records , not the whole table) or pass a parameter to the crystal report (like employee id) so I can filter what the report/pdf file end up displaying.

I posted the code in asp.net - scroll to crystal reports threads.

any suggestions??

bev

Sunday, February 19, 2012

How do I display info on the report parameters on the face of the report ?

I have several parameters used to constrain which data to select from the database.
Examples of prompts for these parameters ;
"Include accesstype:"
"Include activationdate:"
"Include speed data:"
The user chooses Yes or No to each of these.

On the face on the report I want to put some textboxes to display all the parameters with the prompt (as stated above) and the actual value chosen by the user (Y/N). For clarity, I'm not talking about the report parameter area, but about what you will see on a report print-out.

However, working with a parameter in the expression editor, I can only select members Value, Label, Count and IsMultivalue. I would have expected to be able to select "Prompt", but that is not a member of ReportObjectModel.Parameter.

Anyone have a clue ?

BTW - has anyone been able to display a single checkbox for this kind of paramteres ? (Y/N or True/False. A boolean parameter displays as 2 radiobuttons, labelled True and False)

Thanks !

Parameters!ParameterName.Label should give you the value the user selected.

-Geoff

|||

As I stated in my post, I'm aware of the "Label" member. However I want to access the text I wrote in the report parameter form, in the field labelled "Prompt" (in the opper right part of the form) , not the field labelled "Label" (in the "Available values" part of the form) as you suggest .

Consider that there are in fact 3 elements in play for a parameter displayed with a dropdownlist, namely the text which precedes the dropdownlist (this is the one I want to access), the labels displayed in the dropdown and the corresponding values.

Wally :-)

How do I display info on the report parameters on the face of the report ?

I have several parameters used to constrain which data to select from the database.
Examples of prompts for these parameters ;
"Include accesstype:"
"Include activationdate:"
"Include speed data:"
The user chooses Yes or No to each of these.

On the face on the report I want to put some textboxes to display all the parameters with the prompt (as stated above) and the actual value chosen by the user (Y/N). For clarity, I'm not talking about the report parameter area, but about what you will see on a report print-out.

However, working with a parameter in the expression editor, I can only select members Value, Label, Count and IsMultivalue. I would have expected to be able to select "Prompt", but that is not a member of ReportObjectModel.Parameter.

Anyone have a clue ?

BTW - has anyone been able to display a single checkbox for this kind of paramteres ? (Y/N or True/False. A boolean parameter displays as 2 radiobuttons, labelled True and False)

Thanks !

Parameters!ParameterName.Label should give you the value the user selected.

-Geoff

|||

As I stated in my post, I'm aware of the "Label" member. However I want to access the text I wrote in the report parameter form, in the field labelled "Prompt" (in the opper right part of the form) , not the field labelled "Label" (in the "Available values" part of the form) as you suggest .

Consider that there are in fact 3 elements in play for a parameter displayed with a dropdownlist, namely the text which precedes the dropdownlist (this is the one I want to access), the labels displayed in the dropdown and the corresponding values.

Wally :-)