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。同樣的問題是「使用」... –