AttachmentFilename Property
Gets the filename of the attachment.

Namespace: MailBee.Mime
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.4 build 677 for .NET 4.5
Syntax
public string Filename { get; }

Property Value

Type: String
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:

  • If filename parameter of Content-Disposition header is set, its value is passed to this property
  • If filename parameter of Content-Disposition header is missing, name parameter of Content-Type header is used
  • If the value obtained from the previous steps is an empty string, Subject of the message is used
  • If the value obtained from the previous steps is not a unique name (i.e. Attachments collection already contains another attachment with the same Filename), this value is extended with [i] where i is a unique number (1, 2, 3, etc). For instance, picture.gif becomes picture[2].gif if Attachments collection already contains picture.gif and picture[1].gif.

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

Examples
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.
// 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);
}
Running the code above produces the following results:
1.jpg
1[1].jpg
2.jpg
See Also