This documentation is archived and is not being maintained.
MailAttachment Constructor
.NET Framework 1.1
Initializes a new instance of the MailAttachment class.
Overload List
Initializes a new instance of the MailAttachment class with the specified file name for the attachment. Sets the Encoding property to UUEncode by default.
[Visual Basic] Public Sub New(String)
[C#] public MailAttachment(string);
[C++] public: MailAttachment(String*);
[JScript] public function MailAttachment(String);
Initializes a new instance of the MailAttachment class with the specified file name and encoding type for the attachment.
[Visual Basic] Public Sub New(String, MailEncoding)
[C#] public MailAttachment(string, MailEncoding);
[C++] public: MailAttachment(String*, MailEncoding);
[JScript] public function MailAttachment(String, MailEncoding);
Example
[Visual Basic, C#, C++] Note This example shows how to use one of the overloaded versions of the MailAttachment constructor. For other examples that might be available, see the individual overload topics.
[Visual Basic] '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 [C#] //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); } [C++] // This example shows how to programmatically add attached files // to a mail message. MailMessage* myMail = new MailMessage(); // Concatenate a list of attachment files in a string. String* sAttach = S"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[] = {','}; System::Collections::IEnumerator* myEnum = sAttach->Split(delim)->GetEnumerator(); while (myEnum->MoveNext()) { String* sSubstr = __try_cast<String*>(myEnum->Current); MailAttachment* myAttachment = new MailAttachment(sSubstr); myMail->Attachments->Add(myAttachment); }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
See Also
MailAttachment Class | MailAttachment Members | System.Web.Mail Namespace
Show: