Breyta

Deila með


ContentDisposition Class

Definition

Represents a MIME protocol Content-Disposition header.

public ref class ContentDisposition
public class ContentDisposition
type ContentDisposition = class
Public Class ContentDisposition
Inheritance
ContentDisposition

Examples

The following code example creates an email message with an attachment to be displayed inline.

static void CreateMessageInlineAttachment( String^ server, String^ textMessage )
{
   
   // Create a message and set up the recipients.
   MailMessage^ message = gcnew MailMessage( L"jane@contoso.com",L"ben@contoso.com",L"An inline text message for you.",L"Message: " );
   
   // Attach the message string to this email message.
   Attachment^ data = gcnew Attachment( textMessage,MediaTypeNames::Text::Plain );
   
   // Send textMessage as part of the email body.
   message->Attachments->Add( data );
   ContentDisposition^ disposition = data->ContentDisposition;
   disposition->Inline = true;
   
   //Send the message.
   // Include credentials if the server requires them.
   SmtpClient^ client = gcnew SmtpClient( server );
   client->Credentials = CredentialCache::DefaultNetworkCredentials;
   client->Send( message );
   data->~Attachment();
   client->~SmtpClient();
}
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 email message.
    Attachment data = new Attachment(textMessage, MediaTypeNames.Text.Plain);
    // Send textMessage as part of the email 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;

    try
    {
        client.Send(message);
    }
    catch (Exception ex)
    {
        Console.WriteLine("Exception caught in CreateMessageInlineAttachment: {0}",
            ex.ToString());
    }
    data.Dispose();
}

Remarks

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

Email messages are created using instances of the MailMessage class. Instances of the Attachment class are used to add attachments to email 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 https://www.ietf.org.

Constructors

ContentDisposition()

Initializes a new instance of the ContentDisposition class with a DispositionType of Attachment.

ContentDisposition(String)

Initializes a new instance of the ContentDisposition class with the specified disposition information.

Properties

CreationDate

Gets or sets the creation date for a file attachment.

DispositionType

Gets or sets the disposition type for an email attachment.

FileName

Gets or sets the suggested file name for an email attachment.

Inline

Gets or sets a Boolean value that determines the disposition type (Inline or Attachment) for an email attachment.

ModificationDate

Gets or sets the modification date for a file attachment.

Parameters

Gets the parameters included in the Content-Disposition header represented by this instance.

ReadDate

Gets or sets the read date for a file attachment.

Size

Gets or sets the size of a file attachment.

Methods

Equals(Object)

Determines whether the content-disposition header of the specified ContentDisposition object is equal to the content-disposition header of this object.

GetHashCode()

Determines the hash code of the specified ContentDisposition object.

GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a String representation of this instance.

Applies to