Επεξεργασία

Κοινή χρήση μέσω


MailAttachment Constructors

Definition

Initializes a new instance of the MailAttachment class. Recommended alternative: System.Net.Mail.

Overloads

MailAttachment(String)

Initializes a new instance of the MailAttachment class with the specified file name for the attachment. Sets the Encoding property to UUEncode by default. Recommended alternative: System.Net.Mail.

MailAttachment(String, MailEncoding)

Initializes a new instance of the MailAttachment class with the specified file name and encoding type for the attachment. Recommended alternative: System.Net.Mail.

MailAttachment(String)

Initializes a new instance of the MailAttachment class with the specified file name for the attachment. Sets the Encoding property to UUEncode by default. Recommended alternative: 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)

Parameters

filename
String

The name of the attachment file.

Examples

//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

Remarks

The mail attachment file is locked while the mail is being sent.

Applies to

MailAttachment(String, MailEncoding)

Initializes a new instance of the MailAttachment class with the specified file name and encoding type for the attachment. Recommended alternative: 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)

Parameters

filename
String

The name of the attachment file.

encoding
MailEncoding

The type of MailEncoding for the attachment.

Applies to