ContentType.Name プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > ContentType.Name プロパティの意味・解説 

ContentType.Name プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

このインスタンス表される Content-Type ヘッダー内に含まれる名前パラメータの値を取得または設定します

名前空間: System.Net.Mime
アセンブリ: System (system.dll 内)
構文構文

解説解説

次に示す Content-Type ヘッダーの例では、Name プロパティの値は "data.xyz" です。

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

Content-Type ヘッダー構文詳細は、RFC 2045 セクション 5.1 (http://www.ietf.org を参照) に記述されています。

Attachmentコンテンツとして Stream または String指定した場合Name使用して受信者システムでそのコンテンツ格納するファイルの名前を設定できます

使用例使用例

プロパティの値を設定しストリームとして添付するファイルの名前を指定するコード例次に示します

// The following example sends a summary of a log file as the message
// and the log as an e-mail attachment.
public static void SendNamedErrorLog(string
 server, string recipientList)
{
    // Create a message from logMailer@contoso.com to recipientList.
    MailMessage message = new MailMessage(
       "logMailer@contoso.com", recipientList);

    message.Subject = "Error Log report";
    string fileName = "log.txt";
    // Get the file stream for the error log.
    // Requires the System.IO namespace.
    FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
    StreamReader s = new StreamReader(fs);
    int errors = 0;
    while (s.ReadLine() != null)
    {
        // Process each line from the log file here.
        errors++;
    }
    // The e-mail message summarizes the data found in the log.
    message.Body = String.Format("{0} errors in log as of
 {1}",
        errors, DateTime.Now);
    // Close the stream reader. This also closes the file.
    s.Close();
    // Re-open the file at the beginning to make the attachment.
    fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
    // Make a ContentType indicating that the log data
    // that is attached is plain text and is named.
    ContentType ct = new ContentType();
    ct.MediaType = MediaTypeNames.Text.Plain;
    ct.Name = "log" + DateTime.Now.ToString() + ".txt";
    // Create the attachment.
    Attachment data = new Attachment(fs, ct);
    // Add the attachment to the message.
    message.Attachments.Add(data);
    // Send the message.
    // Include credentials if the server requires them.
    SmtpClient client = new SmtpClient(server);
    client.Credentials = CredentialCache.DefaultNetworkCredentials;
    client.Send(message);
    data.Dispose();
    // Close the log file.
    fs.Close();
    return;
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「ContentType.Name プロパティ」の関連用語

ContentType.Name プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ContentType.Name プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS