我有一个数据库字段varbinary,用于存储doc文档和pdf文件。
我想附上这样的流并通过电子邮件发送给我。电子邮件工作正常,没有附件。 我尝试用文件测试(而不是从数据库中检索数据)但是 我被'太多参数'公共子新()'
所困扰请帮忙。
Dim fileName As String = "C:\Users\tzvei\Documents\test.pdf"
' Get the file stream .
' Requires the System.IO namespace.
Dim fs As New FileStream(fileName, FileMode.Open, FileAccess.Read)
Dim ms As New MemoryStream()
ms.SetLength(fs.Length)
fs.Read(ms.GetBuffer(), 0, CInt(fs.Length))
m.Attachments.Add(New Attachment(ms, "test.pdf", "application/pdf")) 'here is the error Too many arguments
ms.Flush()
fs.Close()
ms.Close()`
答案 0 :(得分:0)
谢谢StuartLC 这工作
Dim fileName As String = "C:\Users\tzvei\Documents\ReferenceLetter.pdf"
' Get the file stream for the error log.
' Requires the System.IO namespace.
Dim fs As New FileStream(fileName, FileMode.Open, FileAccess.Read)
Dim mstream As New MemoryStream()
mstream.SetLength(fs.Length)
fs.Read(mstream.GetBuffer(), 0, CInt(fs.Length))
Dim attach1 As New System.Net.Mail.Attachment(mstream, "blah", "application/pdf")
m.Attachments.Add(attach1)