Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use report.ExportToStream function in C#

I'm currently working in c#. I need to convert report file to pdf format and send it through mail. I wrote coding and its working. I use rpt.ExportToDisk(ExportFormatType) for conversion. But it takes long time. Can anyone please suggest me, how to use ExportToStream function, so that i can avoid former one as i dont want the report file to be stored in my disk. This is my code which is working

 rep1.Load(Server.MapPath("CrystalReport_ModbusNode.rpt"));
 rep1.ExportToDisk(ExportFormatType.PortableDocFormat,Server.MapPath("Modbus.pdf"));

I tried this:

rep1.ExportToStream(ExportFormatType.PortableDocFormat);
rep1.SaveAs(Server.MapPath("Modbus.pdf"));

But if I use this, Modbus.pdf is still in rpt format. ExportToStream id not doing any changes?? How can I send mail, without exporting it to my disk. Can anyone help me to solve this issue? Thanks in advance.

like image 775
kousalyarajan Avatar asked May 17 '26 01:05

kousalyarajan


1 Answers

The ExportToStream function returns a Stream. You can then use this stream to write a file. See this answer for details : How do I save a stream to a file in C#?

like image 55
mathieu Avatar answered May 18 '26 15:05

mathieu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!