AttachmentFilename Property |
Gets the filename of the attachment.
Namespace: MailBee.MimeAssembly: MailBee.NET (in MailBee.NET.dll) Version: 12.5.0 build 687 for .NET 4.5
Syntax public string Filename { get; }
Public ReadOnly Property Filename As String
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.
using MailBee;
using MailBee.Mime;
MailMessage msg = new MailMessage();
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");
foreach (Attachment attach in msg.Attachments)
{
Console.WriteLine("Unique filename is " + attach.Filename);
}
Imports MailBee
Imports MailBee.Mime
Dim msg As New MailMessage
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 Each attach As Attachment In msg.Attachments
Console.WriteLine("Unique filename is " & attach.Filename)
Next
Running the code above produces the following results:
See Also