VB.NET - How to convert a crystal report to a html code

Asked By Ajay on 23-Apr-13 09:45 AM
Hey all

I just need to know is there any possible way to convert a crystal report to a html document, so that i would be able to send that code as body of my email.

thanks and regards
Ajay
Robbe Morris replied to Ajay on 23-Apr-13 01:35 PM
The ReportDocument has a method called ExportToStream.  Use the ExportFormatType.HTML40 option as the parameter.

Here's some sample code that reads the output into a byte array.  You can use this to eventually convert it to text.

byte[] buffer = null;
var rpt = new ReportDocument();  // your report object would go here instead.

using (var sr = new StreamReader(rpt.ExportToStream(ExportFormatType.HTML40)))
{
   buffer = new byte[sr.BaseStream.Length];
   sr.BaseStream.Read(buffer, 0, buffer.Length);
   rpt.Close();
   rpt.Dispose();
   rpt = null;
}

Ajay replied to Robbe Morris on 24-Apr-13 03:50 AM
I am not getting correctly sir, which object i should convert to string.
what i am getting string System.byte[] inside the buffer
and i am trying to do it in vb.net

regards
Ajay
Robbe Morris replied to Ajay on 26-Apr-13 08:24 AM
Convert the byte array to a string and send the string as the body of your email (make sure you set the body format as html)

var message = UTF8Encoding.UTF8.GetString(bytes, 0, bytes.Length);