MailAttachment 构造函数

定义

初始化 MailAttachment 类的新实例。 建议使用的替代项:System.Net.Mail

重载

MailAttachment(String)

用附件的指定文件名初始化 MailAttachment 类的新实例。 默认情况下,将 Encoding 属性设置为 UUEncode。 建议使用的替代项:System.Net.Mail

MailAttachment(String, MailEncoding)

用附件的指定文件名和编码类型初始化 MailAttachment 类的新实例。 建议使用的替代项:System.Net.Mail

MailAttachment(String)

用附件的指定文件名初始化 MailAttachment 类的新实例。 默认情况下,将 Encoding 属性设置为 UUEncode。 建议使用的替代项:System.Net.Mail

public:
 MailAttachment(System::String ^ filename);
public MailAttachment (string filename);
new System.Web.Mail.MailAttachment : string -> System.Web.Mail.MailAttachment
Public Sub New (filename As String)

参数

filename
String

附件文件的名称。

示例

//This example shows how to programmatically add attached files 
//to a mail lessage.

MailMessage myMail = new MailMessage();

// Concatenate a list of attachment files in a string.
string sAttach = @"C:\images\image1.jpg,C:\images\image2.jpg,C:\images\image3.jpg";

// Build an IList of mail attachments using the files named in the string.
char[] delim = new char[] {','};
foreach (string sSubstr in sAttach.Split(delim))
{
   MailAttachment myAttachment = new MailAttachment(sSubstr);
   myMail.Attachments.Add(myAttachment);
}
     'This example shows how to programmatically add attachments 
     'to a mail lessage.

     Dim MyMail As MailMessage = New MailMessage()
     Dim iLoop1 As integer
 
     ' Concatenate a list of attachment files in a string.
     Dim sAttach As String = "C:\images\image1.jpg,C:\images\image2.jpg,C:\images\image3.jpg"

     ' Build an IList of mail attachments using the files named in the string.
     Dim delim As Char = ","
     Dim sSubstr As String
     For Each sSubstr in sAttach.Split(delim)
        Dim myAttachment As MailAttachment = New MailAttachment(sSubstr)
        myMail.Attachments.Add(myAttachment)
     Next

注解

邮件附件文件在发送邮件时被锁定。

适用于

MailAttachment(String, MailEncoding)

用附件的指定文件名和编码类型初始化 MailAttachment 类的新实例。 建议使用的替代项:System.Net.Mail

public:
 MailAttachment(System::String ^ filename, System::Web::Mail::MailEncoding encoding);
public MailAttachment (string filename, System.Web.Mail.MailEncoding encoding);
new System.Web.Mail.MailAttachment : string * System.Web.Mail.MailEncoding -> System.Web.Mail.MailAttachment
Public Sub New (filename As String, encoding As MailEncoding)

参数

filename
String

附件文件的名称。

encoding
MailEncoding

附件的 MailEncoding 类型。

适用于