如何将 SQL Server 中存储为二进制对象的 PDF 文件附加到电子邮件中?
我想将在 SQL Server 中作为二进制对象存储的 PDF 文件附加到电子邮件,但不在磁盘上创建(临时)文件。
我已经完成了从 SQL Server 中的二进制字段中以 byte[]
数组形式提取 PDF 文件的第一步。
另外,我还有设置 MailMessage
的步骤:
MailMessage aMailMessage = new MailMessage();
// set address, subject, body
aMailMessage.Attachments.Add(attachment);
我陷入困境的是 attachment
对象:
Attachment attachment = new Attachment(... what goes here? ...);
Attachment
的构造函数主要接受 >string fileName
(我没有但不想要)或 System.IO.Stream contentStream
。
所以我的问题是:使用给定的 byte[] 数组是否可以在磁盘上没有中间文件的情况下创建正确的 Attachment 对象,我需要执行哪些步骤?
先感谢您!
I'd like to attach a PDF file stored as binary object in SQL Server to an email but without creating a (temporary) file on disk.
I already have the first step to pull out the PDF file from the binary field in SQL Server as a byte[]
array.
Also I have the step to setup the MailMessage
:
MailMessage aMailMessage = new MailMessage();
// set address, subject, body
aMailMessage.Attachments.Add(attachment);
Where I am stuck is the attachment
object:
Attachment attachment = new Attachment(... what goes here? ...);
The constructor of Attachment
accepts mainly either a string fileName
(which I don't have and want) or a System.IO.Stream contentStream
.
So my question is: With a given byte[]
array is it possible to create the proper Attachment
object without an intermediary file on disk and what steps do I have to do?
Thank you in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将 byte[] 转换为 MemoryStream 并创建
附件
实例。这是一个例子:You can convert byte[] to MemoryStream and create
Attachment
instance from it. Here is an example: