Share via


ContentDisposition 類別

定義

表示 MIME 通訊協定內容配置標頭。

public ref class ContentDisposition
public class ContentDisposition
type ContentDisposition = class
Public Class ContentDisposition
繼承
ContentDisposition

範例

下列程式代碼範例會建立內嵌顯示附件的電子郵件訊息。

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();
}

備註

類別中的 ContentDisposition 資訊會伴隨電子郵件訊息,其中包含電子郵件訊息傳送至目的地時附件。 中的 ContentDisposition 資訊可由顯示電子郵件的軟體使用,以寄件者預期的方式呈現電子郵件附件。

Email 訊息是使用 類別的MailMessage實例所建立。 類別的 Attachment 實例可用來將附件新增至電子郵件訊息。 若要修改 ContentDisposition 附件的 ,請從 Attachment.ContentDisposition 屬性取得 實例。

要顯示為訊息本文一部分的內容具有的處置類型 Inline。 未顯示但附加於個別檔案中的內容具有的處置類型 AttachmentInline使用屬性來控制與 實例相關聯之附件的ContentDisposition處置類型。

對於檔案附件,您可以使用 的屬性 ContentDisposition 來設定檔案大小,以及建立檔案的日期、上次讀取和上次修改的日期。 針對所有附件,您可以在附件儲存在接收計算機上時設定建議的檔名。

方法 ToString 會傳回 Content-Disposition 標頭。 Content-Disposition 標頭描述於 的 RFC 2183 中 https://www.ietf.org

建構函式

ContentDisposition()

使用 ContentDispositionDispositionType,初始化 Attachment 類別的新執行個體。

ContentDisposition(String)

使用指定的配置資訊,初始化 ContentDisposition 類別的新執行個體。

屬性

CreationDate

取得或設定檔案附件的建立日期。

DispositionType

取得或設定電子郵件附件的配置類型。

FileName

取得或設定電子郵件附件的建議檔案名稱。

Inline

取得或設定 Boolean 值,以判斷電子郵件附件的配置類型 (內嵌或附件)。

ModificationDate

取得或設定檔案附件的修改日期。

Parameters

取得包含在這個執行個體所表示之內容配置標頭中的參數。

ReadDate

取得或設定檔案附件的讀取日期。

Size

取得或設定檔案附件的大小。

方法

Equals(Object)

判斷指定之 ContentDisposition 物件的內容配置標頭是否等於這個物件的內容配置標頭。

GetHashCode()

決定指定 ContentDisposition 物件的雜湊碼。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回這個執行個體的 String 表示。

適用於