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입니다. 이 값의 하위 형식 앞에 세미콜론(;) 구분 기호를 사용하지 않습니다.

예외

Set 작업에 대해 지정된 값이 null입니다.

set 작업에 지정된 값이 Empty("")인 경우

set 작업에 지정된 값이 구문 분석할 수 없는 형식인 경우

예제

다음 코드 예제에서는이 속성의 값을 설정 합니다.

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사용할 수 있습니다.

적용 대상