Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 将内存流附加到电子邮件时参数过多_Asp.net_Vb.net_Stream_Email Attachments - Fatal编程技术网

Asp.net 将内存流附加到电子邮件时参数过多

Asp.net 将内存流附加到电子邮件时参数过多,asp.net,vb.net,stream,email-attachments,Asp.net,Vb.net,Stream,Email Attachments,我有一个存储文档和pdf的数据库字段varbinary 我想附上这样一个流和电子邮件它。电子邮件没有附件也可以正常工作。 我尝试使用文件进行测试,而不是从数据库中检索数据,但是 我被“太多的论据”束缚住了 请帮忙 Dim fileName As String = "C:\Users\tzvei\Documents\test.pdf" ' Get the file stream . ' Requires the System.IO namespace.

我有一个存储文档和pdf的数据库字段varbinary

我想附上这样一个流和电子邮件它。电子邮件没有附件也可以正常工作。 我尝试使用文件进行测试,而不是从数据库中检索数据,但是 我被“太多的论据”束缚住了

请帮忙

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()`      
谢谢你,斯图尔特 这起作用了

   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)

m变量是什么类型的?可能是另一个附件类的副本,可能在范围内,可能是您自己的。Ctor从.NET3.0开始就存在了,所以不是这样。尝试新系统.Net.Mail.Attachment。。。