Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
ContentDisposition Class

Represents a MIME protocol Content-Disposition header.

Namespace:  System.Net.Mime
Assembly:  System (in System.dll)
Visual Basic (Declaration)
Public Class ContentDisposition
Visual Basic (Usage)
Dim instance As ContentDisposition
C#
public class ContentDisposition
Visual C++
public ref class ContentDisposition
JScript
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.

C#
        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;

        try {
        client.Send(message);
      }
      catch (Exception ex) {
        Console.WriteLine("Exception caught in CreateMessageInlineAttachment: {0}", 
                    ex.ToString() );
      }
            data.Dispose();
        }
Visual C++
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 e-mail message.
   Attachment^ data = gcnew 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 = gcnew SmtpClient( server );
   client->Credentials = CredentialCache::DefaultNetworkCredentials;
   client->Send( message );
   data->~Attachment();
   client->~SmtpClient();
}


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 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
creation-date and modification-date bug (date parsing not corresponding to RFC)      kYann ... Thomas Lee   |   Edit   |   Show History
There is some major parsing error. This class does not respect the RFC 822 (Section 5) for date format.

When trying to create a contentdisposition from a string, it throws a FormatException if you :

- Use a zone info like GMT, UT, EST, etc that is authorized by the RFC (see Section 5.1 : Syntax)
- Set the number of seconds to zero in the time string (The RFC specified that the time can be from 00:00:00 to 23:59:59).

The string parsing of this class is very weak and doesn't respect the RFC (RFC822) .
THERE IS NO PARSING ERROR HERE      George_1776   |   Edit   |   Show History
FROM RFC 2183:

quoted-date-time := quoted-string
; contents MUST be an RFC 822 `date-time'
; numeric timezones (+HHMM or -HHMM) MUST be used
THERE IS A BUG!      tb2000 ... Thomas Lee   |   Edit   |   Show History
this: will not parse
attachment; read-date="18 Sep 2009 12:09:00 +0200"; creation-date="18 Sep 2009 12:07:57 +0200"; modification-date="18 Sep 2009 12:09:00 +0200"
fixed to (will parse):
attachment; read-date="18 Sep 2009 12:09:01 +0200"; creation-date="18 Sep 2009 12:07:57 +0200"; modification-date="18 Sep 2009 12:09:01 +0200"

tb
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker