MemoryStream ms = new MemoryStream();
PrintableComponentLink pcl = new PrintableComponentLink(new PrintingSystem());
pcl.Component = ASPxGridViewExporter1;
pcl.Margins.Left = pcl.Margins.Right = 50;
pcl.Landscape = true;
pcl.CreateDocument(false);
pcl.PrintingSystem.Document.AutoFitToPagesWidth = 1;
pcl.ExportToPdf(ms);
MailMessage mailMsg = new MailMessage();
mailMsg.To.Add("[email protected]");
MailAddress mailAddress = new MailAddress("[email protected]");
mailMsg.From = mailAddress;
mailMsg.Subject = "";
mailMsg.Body = "";
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(ms, "x.pdf");
mailMsg.Attachments.Add(attach);
SmtpClient smtpClient = new SmtpClient("192.168.1.200", 25);
smtpClient.UseDefaultCredentials = false;
smtpClient.Send(mailMsg);
ms.Close();
我在附件中获取153B文件。通过邮件发送内存流
我在哪里错了?
将'pcl'包装到'using'语句中,并且完成后,请确保'ms'已刷新并重置为准备好读取,因此MemoryStream无法在附件中工作。 –
@TimS。同样的问题是“使用”... –