ContentType.ToString 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
回傳此 ContentType 物件的字串表示。
public:
override System::String ^ ToString();
public override string ToString();
override this.ToString : unit -> string
Public Overrides Function ToString () As String
傳回
String A 包含目前的設定。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 以來有一個或多個屬性值改變,則 的 ToString 值為以 Content-Type 標頭格式組成的字串,該函式由目前屬性值組合而成。 字串不包含前綴。"Content-type:"
內容型標頭的語法詳見 RFC 2045 第 5.1 節,網址為 https://www.ietf.org。