Click or drag to resize
MimeKit

IMimePartFileName Property

Get or set the name of the file.

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

Property Value

String
The name of the file.
Exceptions
ExceptionCondition
ObjectDisposedException The IMimePart has been disposed.
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.

Example
C#
foreach (var attachment in message.Attachments) {
    if (attachment is MessagePart) {
        var fileName = attachment.ContentDisposition?.FileName;
        var rfc822 = (MessagePart) attachment;

        if (string.IsNullOrEmpty (fileName))
            fileName = "attached-message.eml";

        using (var stream = File.Create (fileName))
            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