I have designed a Report in my ASP.NET web site now i need to provide options to export that report in PDF, HTML, and DOC formats
, how do i achieve that?
crystal report has one button to do that but when ever i try to save that report its saved as .aspx format as i am viewing it in asp.net web page.
try this:
<asp:ImageButton Width="20px" Height="20px" ID="btnPdf" runat="server"
OnClick="btnExport_Click" ImageUrl="~/Images/PDF.png" AlternateText="Export To PDF" CssClass="AddedButton" />
<asp:ImageButton Width="20px" Height="20px" ID="btnXls" runat="server"
OnClick="btnExport_Click" ImageUrl="~/Images/XLS.png" AlternateText="Export To Excel" />
<asp:ImageButton Width="20px" Height="20px" ID="btnDoc" runat="server"
OnClick="btnExport_Click" ImageUrl="~/Images/DOC.png" AlternateText="Export To Word" />
C# code:
protected void btnExport_Click(object sender, EventArgs e)
{
// Stop buffering the response
Response.Buffer = false;
// Clear the response content and headers
Response.ClearContent();
Response.ClearHeaders();
try
{
string senderID = ((ImageButton)sender).ID;
if (senderID == "btnPdf")
reportDocument.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, Page.Title);
else if (senderID == "btnXls")
reportDocument.ExportToHttpResponse(ExportFormatType.ExcelRecord, Response, true, Page.Title);
else if (senderID == "btnDoc")
reportDocument.ExportToHttpResponse(ExportFormatType.WordForWindows, Response, true, Page.Title);
// There are other format options available such as Word, Excel, CVS, and HTML in the ExportFormatType Enum given by crystal reports
}
catch (Exception ex)
{
//error management
}
}
You have to do it by yourself: create a dropdown list with formats you want and a button to make a postback for exporting.
This is an example for the .Net 1.1 / CR9. When making a postback to the following:
MyReport.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
MyReport.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
You can also choose WordForWindows
, RichText
, Excel
, HTML40
and more.Then do the following:
CrystalDecisions.Shared.DiskFileDestinationOptions fileOptions = new DiskFileDestinationOptions();
fileOptions.DiskFileName = "someTmpFileName";
MyReport.DestinationOptions = fileOptions;
MyReport.Export();
You can find more about ExportOptions
class here.
And here is an example for VS 2005 / .Net 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With