Export (0) Print
Expand All

ContentDisposition Class

Note: This class is new in the .NET Framework version 2.0.

Represents a MIME protocol Content-Disposition header.

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

public class ContentDisposition
public class ContentDisposition
public class ContentDisposition

The information in the ContentDisposition class accompanies an e-mail message that contains attachments when the e-mail message is sent to its destination. The information in ContentDisposition can be used by software that displays e-mail to present the e-mail attachments in the manner intended by the sender.

E-mail messages are created using instances of the MailMessage class. Instances of the Attachment class are used to add attachments to e-mail messages. To modify the ContentDisposition for an attachment, get the instance from the Attachment.ContentDisposition property.

Content to be displayed as part of the message body has the disposition type of Inline. Content that is not displayed but is attached in a separate file has the disposition type of Attachment. Use the Inline property to control the disposition type for the attachment associated with an instance of ContentDisposition.

For file attachments, you can use the properties of the ContentDisposition to set the file size, as well as the date the file was created, last read, and last modified. For all attachments, you can set a recommended file name in the event that the attachment is stored on the receiving computer.

The ToString method returns the Content-Disposition header. The Content-Disposition header is described in RFC 2183 available at http://www.ietf.org.

The following code example creates an e-mail message with an attachment to be displayed inline.

public static void CreateMessageInlineAttachment(string server, string
textMessage)
{
    // Create a message and set up the recipients.
    MailMessage message = new MailMessage(
       "jane@contoso.com",
       "ben@contoso.com",
       "An inline text message for you.",
       "Message: ");

    // Attach the message string to this e-mail message.
    Attachment data = new Attachment(textMessage, MediaTypeNames.Text.Plain);
    // Send textMessage as part of the e-mail body.
    message.Attachments.Add(data);
    ContentDisposition disposition = data.ContentDisposition;
    disposition.Inline = true;
    //Send the message.
    // Include credentials if the server requires them.
    SmtpClient client = new SmtpClient(server);
    client.Credentials = CredentialCache.DefaultNetworkCredentials;
    client.Send(message);
    data.Dispose();
}

System.Object
  System.Net.Mime.ContentDisposition

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft