Click or drag to resize
MimeKit

MimePartFileName Property

Gets or sets the name of the file.

Namespace:  MimeKit
Assembly:  MimeKit (in MimeKit.dll) Version: 2.1.0.0
Syntax
C#
public string FileName { get; set; }

Property Value

Type: String
The name of the file.
Remarks

First checks for the "filename" parameter on the Content-Disposition header. If that does not exist, then the "name" parameter on the Content-Type header is used.

When setting the filename, both the "filename" parameter on the Content-Disposition header and the "name" parameter on the Content-Type header are set.

Examples
C#
foreach (var attachment in message.Attachments) {
    if (attachment is MessagePart) {
        var fileName = attachment.ContentDisposition?.FileName :
            (attachment.ContentType.Name ?? "attached.eml");
        var rfc822 = (MessagePart) attachment;

        rfc822.Message.WriteTo (stream);
    } else {
        var part = (MimePart) attachment;
        var fileName = part.FileName;

        using (var stream = File.Create (fileName))
            part.Content.DecodeTo (stream);
    }
}
See Also