Exemple #1
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            // open regular output stream
            string fileName = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + @"\out.htm";
            Stream s        = new FileStream(fileName, FileMode.Create);

            // render report to stream
            Cursor = Cursors.WaitCursor;
            _c1r.RenderToStream(s, C1.C1Report.FileFormatEnum.HTML);
            Cursor = Cursors.Default;

            // close stream
            s.Close();

            // show what we got
            System.Diagnostics.Process.Start(fileName);
        }
Exemple #2
0
        private void SendMessage(bool useAttachment)
        {
            // @"c:\temp\test\report.html";
            string fname = Path.GetTempPath() + @"\c1_report.html";

            // create message
            MailMessage msg = new MailMessage();

            msg.From = "C1Report";
            msg.To   = "*****@*****.**";

            // add body
            if (useAttachment)
            {
                // create attachment
                _c1r.RenderToFile(fname, C1.C1Report.FileFormatEnum.HTMLDrillDown);
                MailAttachment att = new MailAttachment(fname);

                // add body
                msg.Subject = "Test HTML attachment.";
                msg.Body    = "HTML report is attached.";
                msg.Attachments.Add(att);
            }
            else
            {
                // render to stream
                MemoryStream ms = new MemoryStream();
                _c1r.RenderToStream(ms, C1.C1Report.FileFormatEnum.HTMLDrillDown);
                string body = Encoding.UTF8.GetString(ms.GetBuffer());

                // add body
                msg.Subject    = "Test HTML body.";
                msg.BodyFormat = MailFormat.Html;
                msg.Body       = body;
            }

            // send the message
            try
            {
                SmtpMail.SmtpServer = "YOUR.SMTP.SERVER.HERE";                 // << your mail server goes here
                SmtpMail.Send(msg);
                MessageBox.Show("Message sent successfully");
            }
            catch (Exception x)
            {
                MessageBox.Show(x.Message);
            }

            // clean up
            if (File.Exists(fname))
            {
                File.Delete(fname);
            }
        }