MailBee.NET Objects 4.0

AttachmentCollection.Item Property (Int32)

Gets or sets the Attachment object at the specified zero-based index in the collection.

public Attachment this[
   int index
] {get; set;}

Parameters

index
The zero-based index number of the attachment in the collection.

Property Value

An Attachment object having the specified zero-based index in the collection.

Exceptions

Exception Type Condition
ArgumentOutOfRangeException The specified index does not exist.

Example

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

// When there are any attachments...
if (msg.Attachments.Count > 0)
{
    // Get the attachment by its index.
    Attachment attach = msg.Attachments[0];

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

' When there are any attachments...
If msg.Attachments.Count > 0 Then
    ' Get the attachment by its index.
    Dim attach As Attachment = msg.Attachments(0)

    ' 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