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の文字列形式を表示します。

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 が作成されてから 1 つ以上のプロパティ値が変更された場合、 ToString の値は、現在のプロパティ値を使用して構成される Content-Type ヘッダーの形式の文字列になります。 文字列には、 "Content-type:" プレフィックスは含まれません。

Content-Type ヘッダーの構文については、RFC 2045 セクション 5.1 で説明 https://www.ietf.org

適用対象