[英]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.