简体   繁体   English

在 outlook 中添加 XtraReport 作为附件

[英]Add XtraReport as attachment in outlook

This Is my code:这是我的代码:

   using (RepMissingStatusProject report = new RepMissingStatusProject())
        {
            report.DataSource = await inventory.RepMissingStatusProject(Convert.ToInt32(oListProject.cmbProject.EditValue)).ConfigureAwait(true);
            report.CreateDocument();

            Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
            Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

            MemoryStream mem = new MemoryStream();
            report.ExportToPdf(mem);
            mem.Seek(0, System.IO.SeekOrigin.Begin);

            oMsg.To = "Test@Test.com";
            oMsg.Subject = "Test";
            oMsg.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML;
            oMsg.Display(false); 
            oMsg.HTMLBody = "Veuillez trouver ci-joint:" + "<br />" + oMsg.HTMLBody;
            oMsg.Attachments.Add(mem, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);
        }

the outlook open fine and all data are correct except for the attachment file I get this error: outlook 打开正常,所有数据都正确,除了附件文件我收到此错误:

System.Runtime.InteropServices.COMException: 'Member not found. System.Runtime.InteropServices.COMException:'未找到成员。 (Exception de HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))' (HRESULT 异常:0x80020003 (DISP_E_MEMBERNOTFOUND))'

How can I solve this problem?.我怎么解决这个问题?。
Thanks in advance for your help在此先感谢您的帮助

Update:更新:
I try to use this code我尝试使用此代码

System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType(System.Net.Mime.MediaTypeNames.Application.Pdf);
System.Net.Mail.Attachment attach = new System.Net.Mail.Attachment(mem,ct);
attach.ContentDisposition.FileName = "État De Manque.pdf";

but i get another error但我得到另一个错误

System.ArgumentException HResult=0x80070057 Message=Sorry, something went wrong. System.ArgumentException HResult=0x80070057 Message=抱歉,出了点问题。 You may want to try again.您可能想再试一次。 StackTrace "at Microsoft.Office.Interop.Outlook.Attachments.Add(Object Source, Object Type, Object Position, Object DisplayName)\r\n at Smart_Industrial_Management.PL.FrmInventory.d__44.MoveNext() in D:\SIM Windows7\Smart Industrial Management\PL\FrmInventory.cs:line 859" string StackTrace "at Microsoft.Office.Interop.Outlook.Attachments.Add(Object Source, Object Type, Object Position, Object DisplayName)\r\n at Smart_Industrial_Management.PL.FrmInventory.d__44.MoveNext() in D:\SIM Windows7\智能工业管理\PL\FrmInventory.cs:line 859" 字符串

oMsg.Attachments.Add(mem

the first argument should be the path to file on your file system.第一个参数应该是文件系统上文件的路径。 so you need to export pdf to file (with randomly generated name) and put the path into the oMsg.Attachments.Add() method call as first argument.因此您需要将 pdf 导出到文件(具有随机生成的名称)并将路径作为第一个参数放入 oMsg.Attachments.Add() 方法调用中。

so your code should be lilke所以你的代码应该是 lilke

report.ExportToPdf(randomName);
...
oMsg.Attachments.Add(randomName,...);
File.Delete(randomName);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将生成的附件添加到Outlook电子邮件 - Add generated attachment to Outlook email 参考 Sharepoint 文档添加 Outlook 附件 - Add Outlook attachment by reference to Sharepoint document 添加附件上下文菜单Outlook 2013 - Add attachment context menu Outlook 2013 Outlook加载项无法读取附件路径 - Outlook add-in failed to read attachment path Outlook加载项禁用JPEG附件的自动压缩 - Outlook add-in disable automatic compression of JPEG attachment C#:将资源添加为Outlook邮件项的附件 - C#: add a resource as an attachment to an Outlook mail item 互操作 Outlook - 如何将 bitmap 添加到邮件正文/附件中 - Interop Outlook - How to add bitmap into mail body/attachment C#中的Outlook加载项(保存附件并添加对已保存文件路径的url引用作为附件) - Add-in for Outlook in C# (Saving the Attachment and adding a url reference to the saved file path as attachment) 如果我通过链接添加“Outlook项目”类型的附件或共享文档,Outlook附件包含一些未知图像“image00001” - Outlook attachment contains some unknown images “image00001” if I add “Outlook Item” type of attachment or share document via link 创建邮件时,请在Outlook加载项(C#)中读取Outlook附件内容 - Read Outlook attachment content in Outlook add-in (C# ) while creating a mail
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM