ContentType.MediaType プロパティ

定義

このインスタンスで表される Content-Type ヘッダー内に含まれるメディア タイプの値を取得または設定します。

public:
 property System::String ^ MediaType { System::String ^ get(); void set(System::String ^ value); };
public string MediaType { get; set; }
member this.MediaType : string with get, set
Public Property MediaType As String

プロパティ値

メディア タイプおよびサブタイプの値を格納している String。 この値には、サブタイプの後にセミコロン (;) の区切り記号は含まれていません。

例外

設定操作に指定された値は null です。

設定操作に指定された値は Empty ("") です。

設定操作として指定した値が、解析できない形式です。

次のコード例では、このプロパティの値を設定します。

static void CreateMessageInlineAttachment2( 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"A text message for you.",L"Message: " );
   
   // Attach the message string to this email message.
   Attachment^ data = gcnew Attachment( textMessage );
   
   // Send textMessage as part of the email body.
   message->Attachments->Add( data );
   ContentType^ content = data->ContentType;
   content->MediaType = MediaTypeNames::Text::Plain;
   
   //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 CreateMessageInlineAttachment2(string server, string
textMessage)
{
    // Create a message and set up the recipients.
    MailMessage message = new MailMessage(
       "jane@contoso.com",
       "ben@contoso.com",
       "A text message for you.",
       "Message: ");

    // Attach the message string to this email message.
    Attachment data = new Attachment(textMessage);
    // Send textMessage as part of the email body.
    message.Attachments.Add(data);
    ContentType content = data.ContentType;
    content.MediaType = MediaTypeNames.Text.Plain;
    //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 CreateMessageInlineAttachment2: {0}",
            ex.ToString());
    }
    data.Dispose();
}

注釈

次の Content-Type ヘッダーの例では、 プロパティの MediaType 値は です "application/x-myType"

content-type: application/x-myType; name=data.xyz

ヘッダーから名前情報を null 削除するには、このプロパティを または String.Empty に設定します。

Content-Type ヘッダーの構文については、RFC 2045 セクション 5.1 を参照してください。 RFC 2046 では、MIME メディアの種類に関する詳細情報が提供されます。 これらの RFC は、 で https://www.ietf.org使用できます。

適用対象