This documentation is archived and is not being maintained.

Attachment.ContentDisposition Property

Gets the MIME content disposition for this attachment.

Namespace: System.Net.Mail
Assembly: System (in system.dll)

public ContentDisposition ContentDisposition { get; }
/** @property */
public ContentDisposition get_ContentDisposition ()

public function get ContentDisposition () : ContentDisposition

Not applicable.

Property Value

A ContentDisposition that provides the presentation information for this attachment.

The information in the ContentDisposition class represents the MIME Content-Disposition header. This header is described in RFC 2183, available at

The following code example gets the ContentDisposition for an attachment and displays its properties.

public static void CreateMessageAttachment1(string server, string textMessage)
    // Create a message and set up the recipients.
    MailMessage message = new MailMessage(
       "A text message for you.",
       "Message: ");

    // Attach the message string to this e-mail message.
    Attachment data = new Attachment(textMessage, MediaTypeNames.Text.Plain);
    ContentDisposition disposition = data.ContentDisposition;
    // Suggest a file name for the attachment.
    disposition.FileName = "message" + DateTime.Now.ToString();
    //Send the message.
    SmtpClient client = new SmtpClient(server);
    client.Credentials = CredentialCache.DefaultNetworkCredentials;
    // Display the values in the ContentDisposition for the attachment.
    Console.WriteLine("Content disposition");
    Console.WriteLine("File {0}", disposition.FileName);
    Console.WriteLine("Size {0}", disposition.Size);
    Console.WriteLine("Creation {0}", disposition.CreationDate);
    Console.WriteLine("Modification {0}", disposition.ModificationDate);
    Console.WriteLine("Read {0}", disposition.ReadDate);
    Console.WriteLine("Inline {0}", disposition.Inline);
    Console.WriteLine("Parameters: {0}", disposition.Parameters.Count);
    foreach (DictionaryEntry d in disposition.Parameters)
        Console.WriteLine("{0} = {1}", d.Key, d.Value);

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0