Share via


ContentType.ToString 메서드

정의

ContentType 개체의 문자열 표현을 반환합니다.

public:
 override System::String ^ ToString();
public override string ToString ();
override this.ToString : unit -> string
Public Overrides Function ToString () As String

반환

String에 대한 현재 설정이 들어 있는 ContentType입니다.

예제

다음 코드 예제에서는 의 문자열 표현을 표시 합니다 ContentType.

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

설명

메서드의 ToString 값에는 이 ContentType를 만드는 데 사용되는 문자열이 포함되어 있습니다. 이 문자열이 지정되었고 속성 값이 변경되지 않은 경우 입니다. 문자열을 지정하지 않거나 하나 이상의 속성 값이 ContentType 생성된 이후 변경된 경우 값 ToString 은 현재 속성 값을 사용하여 구성된 Content-Type 헤더 형식의 문자열입니다. 문자열에는 접두사를 "Content-type:" 포함하지 않습니다.

Content-Type 헤더의 구문은 에서 사용할 수 있는 RFC 2045 섹션 5.1에 https://www.ietf.org설명되어 있습니다.

적용 대상