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

I am Shailendra.

I am doing Crystal Report convert to PDF and print button on button click event.
Please any one help me. It is very urgent.

This is my code and I got error path is Invalid.
C#
ReportDocument crystalReport = new ReportDocument();
MemoryStream oStream = new MemoryStream(); // using System.IO
oStream = (MemoryStream)
crystalReport.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
    //crystalReport.ExportToStream(CrystalDecisions.Shared.ExportFormatType.ExcelRecord);
HttpContext.Current.Response.ClearContent(); //Clear the content
HttpContext.Current.Response.ClearHeaders(); //Clear the Headers
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.AddHeader("Content-Disposition", "inline; filename=Report.pdf");
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/pdf";
Response.BinaryWrite(oStream.ToArray());
Response.End();

Thank you In Advance.
Posted
Updated 6-Apr-12 6:56am
v2

before below statement,
HTML
HttpContext.Current.Response.AddHeader("Content-Disposition", "inline; filename=Report.pdf");


you can set a string variable and set path to it.

C#
string strPath=server.mappath(); 

then
C#
"inline; filename="  + strPath + "Report.pdf".
 
Share this answer
 
v2
C#
MemoryStream oStream; // using System.IO
        oStream = (MemoryStream)
        rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.ExcelRecord);
       Response.Clear();
        Response.Buffer = true;
        Response.ContentType = "application/vnd.ms-excel";
        Response.BinaryWrite(oStream.ToArray());
        Response.End();

Use This
 
Share this answer
 
v2

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