MailBee.NET Objects 7.2

Attachment.Filename Property

Gets the filename of the attachment.

public string Filename {get;}

Property Value

A string containing the filename of the attachment. The value is NEVER an empty string.

Remarks

Within the Attachments collection, every attachment has the unique Filename.

Filename property value is set accordingly the following considerations:

To get the real name of the attached file (as it appears in the e-mail message), use FilenameOriginal property.

Thus, Filename is usually equal to FilenameOriginal of the same attachment, but it may be different sometimes.

Other useful properties are Name (gets the friendly name of the attachment if available) and SavedAs (gets the full path to the file if the attachment was saved to disk).

Example

This sample creates a new message, attaches 3 files, and displays the unique filename for each attached file. The sample demonstrates attaching files which will have the same filenames in the e-mail message (although their source locations are different). The message will have 1.jpg, 1.jpg and 2.jpg attachments (these will be their FilenameOriginal values) while their unqiue Filename values will be 1.jpg, 1[1].jpg and 2.jpg.

[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)

// Create a new MailMessage object.
MailMessage msg = new MailMessage();

// Attach some files.
msg.Attachments.Add(@"C:\Temp\My_Images\1.jpg", "1.jpg");
msg.Attachments.Add(@"C:\Temp\My_Images\2.jpg", "1.jpg");
msg.Attachments.Add(@"C:\Temp\Other_Images\1.jpg", "2.jpg");

// For every attachment...
foreach (Attachment attach in msg.Attachments)
{
    // ...show the unique filename of the attachment.
    Console.WriteLine("Unique filename is " + attach.Filename);
}
[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)

' Create a new MailMessage object.
Dim msg As New MailMessage

' Attach some files.
msg.Attachments.Add("C:\Temp\My_Images\1.jpg", "1.jpg")
msg.Attachments.Add("C:\Temp\My_Images\2.jpg", "1.jpg")
msg.Attachments.Add("C:\Temp\Other_Images\1.jpg", "2.jpg")

' For every attachment...
For Each attach As Attachment In msg.Attachments
    ' ...show the unique filename of the attachment.
    Console.WriteLine("Unique filename is " & attach.Filename)
Next
Running the code above produces the following results:
1.jpg
1[1].jpg
2.jpg

See Also

Attachment Class | MailBee.Mime Namespace | Name | SavedAs | FilenameOriginal