Content Typeとは? わかりやすく解説

ContentType クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

MIME プロトコルの Content-Type ヘッダー表します

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

public class ContentType
public ref class ContentType
public class ContentType
public class ContentType
解説解説
使用例使用例

添付データ含んだ電子メール メッセージ作成し添付データの ContentDisposition プロパティ表示するコード例次に示します

public static void CreateMessageWithAttachment(string
 server)
{
    // Specify the file to be attached and sent.
    // This example assumes that a file named Data.xls exists in the
    // current working directory.
    string file = "data.xls";
    // Create a message and set up the recipients.
    MailMessage message = new MailMessage(
       "jane@contoso.com",
       "ben@contoso.com",
       "Quarterly data report.",
       "See the attached spreadsheet.");

    // Create  the file attachment for this e-mail message.
    Attachment data = new Attachment(file, MediaTypeNames.Application.Octet);
    // Add time stamp information for the file.
    ContentDisposition disposition = data.ContentDisposition;
    disposition.CreationDate = System.IO.File.GetCreationTime(file);
    disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
    disposition.ReadDate = System.IO.File.GetLastAccessTime(file);
    // Add the file attachment to this e-mail message.
    message.Attachments.Add(data);
    //Send the message.
    SmtpClient client = new SmtpClient(server);
    // Add credentials if the SMTP server requires them.
    client.Credentials = CredentialCache.DefaultNetworkCredentials;
    client.Send(message);
    // Display the values in the ContentDisposition for the attachment.
    ContentDisposition cd = data.ContentDisposition;
    Console.WriteLine("Content disposition");
    Console.WriteLine(cd.ToString());
    Console.WriteLine("File {0}", cd.FileName);
    Console.WriteLine("Size {0}", cd.Size);
    Console.WriteLine("Creation {0}", cd.CreationDate);
    Console.WriteLine("Modification {0}", cd.ModificationDate);
    Console.WriteLine("Read {0}", cd.ReadDate);
    Console.WriteLine("Inline {0}", cd.Inline);
    Console.WriteLine("Parameters: {0}", cd.Parameters.Count);
    foreach (DictionaryEntry d in cd.Parameters)
    {
        Console.WriteLine("{0} = {1}", d.Key, d.Value);
    }
    data.Dispose();
}
継承階層継承階層
System.Object
  System.Net.Mime.ContentType
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ContentType メンバ
System.Net.Mime 名前空間
SmtpClient クラス
MailMessage クラス

ContentType コンストラクタ ()

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

ContentType クラス新し既定インスタンス初期化します。

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

public ContentType ()
public:
ContentType ()
public ContentType ()
解説解説

このコンストラクタは、MediaType プロパティ"application/octet-stream"初期化します。

使用例使用例

このコンストラクタ呼び出す方法次のコード例示します

// 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;
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ContentType クラス
ContentType メンバ
System.Net.Mime 名前空間

ContentType コンストラクタ (String)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

指定した文字列使用して、ContentType クラス新しインスタンス初期化します。

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

Public Sub New ( _
    contentType As String _
)
Dim contentType As String

Dim instance As New ContentType(contentType)
public ContentType (
    string contentType
)
public:
ContentType (
    String^ contentType
)
public ContentType (
    String contentType
)
public function ContentType (
    contentType : String
)

パラメータ

contentType

MIMEメディア タイプサブタイプ、および省略可能なパラメータ格納している String (たとえば、"text/plain; charset=us-ascii")。

例外例外
例外種類条件

ArgumentNullException

contentTypenull 参照 (Visual Basic では Nothing) です。

ArgumentException

contentTypeEmpty ("") です。

FormatException

contentType が、解析できない形式です。

解説解説

contentType 文字列構文については、RFC 2045 セクション 5.1 (http://www.ietf.org) を参照してください

使用例使用例

このコンストラクタ呼び出す方法次のコード例示します

// 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;
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ContentType クラス
ContentType メンバ
System.Net.Mime 名前空間

ContentType コンストラクタ


ContentType プロパティ


ContentType メソッド


ContentType メンバ

MIME プロトコルの Content-Type ヘッダー表します

ContentType データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

ContentType クラス
System.Net.Mime 名前空間
SmtpClient クラス
MailMessage クラス

メディアタイプ

(Content Type から転送)

出典: フリー百科事典『ウィキペディア(Wikipedia)』 (2023/12/02 08:06 UTC 版)

メディアタイプ(日: メディア型[1]: Media Type(s))は、ファイルやインターネット上で転送されるコンテンツの形式を表現する識別子である。MIMEタイプ要素タイプ (Content type)とも表記される。text/plainのように、スラッシュで区切る表記が特徴的である。


注釈

  1. ^ RFC 6838 3. Registration Trees and Subtype NamesよりThe following subsections define registration "trees" that are distinguished by the use of faceted names, e.g., subtype names that begin with a "tree." prefix.[9]
  2. ^ RFC 6838 3.1. Standards TreeよりMedia types in the standards tree MUST NOT have faceted names, unless they are grandfathered in using the process described in Appendix A.[9]
  3. ^ RFC 6838 3.4. Unregistered x. TreeよりHowever, with the simplified registration procedures described above for vendor and personal trees, it should rarely, if ever, be necessary to use unregistered types. Therefore, use of types in the "x." tree is strongly discouraged.[9]

出典

  1. ^ a b c d e f g JIS X 5810-2:2008「多目的インターネットメール拡張 (MIME) ―第2部: メディア型」日本産業標準調査会経済産業省
  2. ^ "Media Types". Hypertext Transfer Protocol -- HTTP/1.0 (英語). May 1996. sec. 3.6. doi:10.17487/RFC1945. RFC 1945
  3. ^ HTML 4.01 Specification” (1999年12月24日). 2017年2月2日閲覧。
  4. ^ Media Type Registration Procedure (英語). March 1994. p. 1. doi:10.17487/RFC1590. RFC 1590. These types, previously called "MIME Types", are now called "Media Types".
  5. ^ MIME Sniffing Standard” (英語). WHATWG. 2017年3月26日閲覧。 “A MIME type is sometimes called an Internet media type in protocol literature, but consistently using the term MIME type avoids confusion with the use of "media type" as described in the Media Queries CSS specification.”
  6. ^ Daniel Leidert, Egon Willighagen (2007年). “The chemical-mime-data project”. 2016年10月8日時点のオリジナルよりアーカイブ。2016年4月28日閲覧。
  7. ^ Chemical MIME Home page”. 2019年5月11日閲覧。
  8. ^ S. Rzepa, Henry; Murray-Rust, Peter; J. Whitaker, Benjamin (1998-08-14). “The Application of Chemical Multipurpose Internet Mail Extensions (Chemical MIME) Internet Standards to Electronic Mail and World Wide Web Information Exchange”. Journal of Chemical Information and Modeling (American Chemical Society). doi:10.1021/ci9803233. https://pubs.acs.org/doi/10.1021/ci9803233. 
  9. ^ a b c d e f g Media Type Specifications and Registration Procedures (英語). January 2013. doi:10.17487/RFC6838. RFC 6838
  10. ^ Berjon, Robin (2014年5月14日). “application/x-www-form-urlencoded” (英語). IANA. 2017年3月26日閲覧。


「メディアタイプ」の続きの解説一覧

Content-Type

出典: フリー百科事典『ウィキペディア(Wikipedia)』 (2020/03/24 07:00 UTC 版)

Multipurpose Internet Mail Extensions」の記事における「Content-Type」の解説

メディアタイプ」も参照 このメッセージ中のデータの種類指定する一般的な書式次の通り。 Content-Type: type/subtype; parameter type大分類となるデータの種類指定するsubtypeにはより詳細形式指定するparameter追加情報指定するもので、複数指定できる電子メールメッセージにおいて使われる例を以下に示す。 text/plain; charset=iso-2022-jp; format=flowed; delsp=yes(プレーンテキストISO-2022-JPRFC 3676 で規定されるflowedおよびdelspの文字列折り返し処理を適用) text/html; charset=UTF-8HTMLテキストUTF-8) multipart/alternative(HTMLメールにおいて、HTMLによるメッセージ同等プレーンテキストによるメッセージ用意する場合のように、同じ情報異な形式表したマルチパート) type毎に未知subtype扱い規定されており、受信側自分扱えないsubtypeであっても最低限取り扱いが可能となる。text場合は text/plain、application/octet-stream、multipart場合は multipart/mixed である。applicationimageaudiovideoなどは、未知subtypeについてapplication/octet-streamとして扱うよう規定している。

※この「Content-Type」の解説は、「Multipurpose Internet Mail Extensions」の解説の一部です。
「Content-Type」を含む「Multipurpose Internet Mail Extensions」の記事については、「Multipurpose Internet Mail Extensions」の概要を参照ください。

ウィキペディア小見出し辞書の「Content Type」の項目はプログラムで機械的に意味や本文を生成しているため、不適切な項目が含まれていることもあります。ご了承くださいませ。 お問い合わせ


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

辞書ショートカット

すべての辞書の索引

「Content Type」の関連用語

Content Typeのお隣キーワード
検索ランキング

   

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



Content Typeのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.
ウィキペディアウィキペディア
All text is available under the terms of the GNU Free Documentation License.
この記事は、ウィキペディアのメディアタイプ (改訂履歴)の記事を複製、再配布したものにあたり、GNU Free Documentation Licenseというライセンスの下で提供されています。 Weblio辞書に掲載されているウィキペディアの記事も、全てGNU Free Documentation Licenseの元に提供されております。
ウィキペディアウィキペディア
Text is available under GNU Free Documentation License (GFDL).
Weblio辞書に掲載されている「ウィキペディア小見出し辞書」の記事は、WikipediaのMultipurpose Internet Mail Extensions (改訂履歴)の記事を複製、再配布したものにあたり、GNU Free Documentation Licenseというライセンスの下で提供されています。

©2024 GRAS Group, Inc.RSS