MailBee.NET Objects 4.0

AttachmentCollection.Item Property (String)

Gets the Attachment object in the collection by the specified filename.

public Attachment this[
   string filename
] {get;}

Parameters

filename
The unique filename of the attachment in the collection (as returned by the Filename property).

Property Value

An Attachment object having the specified unique filename, or a null reference (Nothing in Visual Basic) if the attachment with the specified unique filename does not exist in the collection.

Example

This sample loads the message from .EML file and saves the specified attachment 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");

// Access the attachment in the collection by the unique name.
Attachment attach = msg.Attachments["my_photo.jpg"];

// When there is an attachment...
if (attach != null)
{
    // Save the attachment to folder.
    attach.SaveToFolder(@"C:\Temp", 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")

' Access the attachment in the collection by the unique name.
Dim attach As Attachment = msg.Attachments("my_photo.jpg")

' When there is an attachment...
If Not attach Is Nothing Then
    ' Save the attachment to the folder.
    attach.SaveToFolder("C:\Temp", True)
End If

See Also

AttachmentCollection Class | MailBee.Mime Namespace | AttachmentCollection.Item Overload List | Item