MailBee.NET Objects 4.0

Attachment.Save Method 

Saves the content of the attachment into the specified file.

public bool Save(
   string filename,
   bool overwrite
);

Parameters

filename
The absolute or relative path under which to save the attachment.
overwrite
Denotes if the file must be overwritten if it already exists.

Return Value

true if the attachment was successfully saved to disk; otherwise, false.

Remarks

The developer can use SaveToFolder method to save the attachment into specified folder under the actual filename of the attachment.

Note   If overwrite is false and the file with the same filename already exists, the attachment will be saved under another name. For instance, if cat.gif is being saved and such file already exists, it will be actually saved as cat[1].gif. The developer can use SavedAs property to obtain the filename of the saved file.

Exceptions

Exception Type Condition
MailBeeIOException An error occurred and ThrowExceptions is true.

Example

This sample loads the message from .EML file and saves all the attachments to disk.

[C#]
// To use the code below, import MailBee namespaces at the top of your code.
using MailBee;
using MailBee.Mime;

// The actual code (put it into a method of your class)

// Load the message from file.
MailMessage msg = new MailMessage();
msg.LoadMessage(@"C:\Docs\TestMail.eml");

// For every attachment...
foreach (Attachment attach in msg.Attachments)
{
    // ...save it to disk.
    attach.Save(@"C:\Temp\" + attach.Filename, true);
}
[Visual Basic]
' To use the code below, import MailBee namespaces at the top of your code.
Imports MailBee
Imports MailBee.Mime

' The actual code (put it into a method of your class)

' Load the message from file.
Dim msg As New MailMessage
msg.LoadMessage("C:\Docs\TestMail.eml")

' For every attachment... 
For Each attach As Attachment In msg.Attachments
    ' ...save it to disk.
    attach.Save("C:\Temp\" & attach.Filename, True)
Next

See Also

Attachment Class | MailBee.Mime Namespace | SaveToFolder