【问题标题】:Send email from telerik report viewer从 Telerik 报告查看器发送电子邮件
【发布时间】:2016-02-09 08:18:50
【问题描述】:

我想以 pdf 附件的形式发送一封电子邮件,而无需从 Telerik 报告查看器的某处保存/导出它,但我找不到方法。

此外,当我处于调试模式并查看设计器时,我看到了这个按钮,并且属性上没有任何电子邮件。

当我在浏览器上运行项目时,此按钮不显示。 有谁知道为什么?

我尝试使用此代码制作一个按钮,但我无法将我的代码中的报告转换为 pdf。

 protected void RadButton1_Click(object sender, EventArgs e)
        {
            string type = Request.Params["type"];
            string no = Request.Params["no"];
            string stat = Request.Params["stat"];

            //Session["compcode"] = Request.Params["compcode"];

            var instanceReportSource = new Telerik.Reporting.InstanceReportSource();
            instanceReportSource.ReportDocument = new Reports.Report1();
            instanceReportSource.Parameters.Add("docno", no);
            instanceReportSource.Parameters.Add("doctype", type);
            instanceReportSource.Parameters.Add("docstat", stat);

            try
            {
                // Create the Outlook application.
                Outlook.Application oApp = new Outlook.Application();
                // Create a new mail item.
                Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
                // Set HTMLBody. 
                //add the body of the email
                oMsg.HTMLBody = "Hello, Jawed your message body will go here!!";
                //Add an attachment.
                String sDisplayName = "MyAttachment";
                int iPosition = (int)oMsg.Body.Length + 1;
                int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
                //now attached the file
                Outlook.Attachment oAttach = oMsg.Attachments.Add("here must be the report as pdf", iAttachType, iPosition, sDisplayName);
                //Subject line
                oMsg.Subject = "Your Subject will go here.";
                // Add a recipient.
                Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
                // Change the recipient in the next line if necessary.
                Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add("xxxxx@gmail.com");
                oRecip.Resolve();
                // Send.
                oMsg.Send();
                // Clean up.
                oRecip = null;
                oRecips = null;
                oMsg = null;
                oApp = null;
            }//end of try block
            catch (Exception ex)
            {
                string ep = ex.ToString();
            }//end of catch


        }

【问题讨论】:

    标签: c# asp.net telerik email-attachments telerik-reporting


    【解决方案1】:

    您在上面圈出的按钮是显示/隐藏报表查看器的参数区域。如果您查看报告查看器的文档,它将解释如何自定义工具栏,这将允许您在工具栏上添加一个电子邮件按钮。然后在您的代码中,您必须将报告以某种格式(可能是 pdf)呈现到内存流中,然后将其附加到您的电子邮件引擎。他们在这里有一个如何通过电子邮件发送报告的旧示例:http://www.telerik.com/blogs/send-telerik-report-as-email-attachment

    【讨论】:

    • 这对我没有帮助,不清楚如何创建自定义工具栏。
    • 您可以通过覆盖 ReportViewer TargetType 的样式来创建自定义工具栏。我建议您在 Telerik 博客中搜索有关您正在使用的 ReportViewer 版本的示例。
    猜你喜欢
    • 1970-01-01
    • 2012-05-07
    • 2019-04-17
    • 1970-01-01
    • 1970-01-01
    • 2013-02-18
    • 2021-05-06
    • 2012-09-08
    • 1970-01-01
    相关资源
    最近更新 更多