How to use report.ExportToStream function in C#

2019-07-17 17:00发布

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.

1条回答
Luminary・发光体
2楼-- · 2019-07-17 18:00

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#?

查看更多
登录 后发表回答