ContentType クラス
アセンブリ: System (system.dll 内)
構文
解説
ContentType クラスの情報は、電子メールを表示するソフトウェアが、そのコンテンツを適切に表すことができるような方法で電子メール メッセージに格納されたデータを記述するために使用されます。ContentType は、添付データのコンテンツの種類を指定するために Attachment クラスで使用されます。
Content-Type ヘッダーの構文については、RFC 2045 セクション 5.1 を参照してください。RFC 2046 では、MIME メディア タイプとそれらのパラメータに関する詳細情報が提供されています。これらの RFC については http://www.ietf.org を参照してください。
添付データを含んだ電子メール メッセージを作成し、添付データの 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.Net.Mime.ContentType
プラットフォーム
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
ContentType コンストラクタ ()
アセンブリ: System (system.dll 内)
構文
解説
使用例
// 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; }
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
ContentType コンストラクタ (String)
アセンブリ: System (system.dll 内)
構文
例外
使用例
// 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; }
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
ContentType コンストラクタ
オーバーロードの一覧
名前 | 説明 |
---|---|
ContentType () | ContentType クラスの新しい既定のインスタンスを初期化します。 |
ContentType (String) | 指定した文字列を使用して、ContentType クラスの新しいインスタンスを初期化します。 |
ContentType プロパティ
パブリック プロパティ
名前 | 説明 | |
---|---|---|
Boundary | このインスタンスで表される Content-Type ヘッダー内に含まれる境界パラメータの値を取得または設定します。 | |
CharSet | このインスタンスで表される Content-Type ヘッダー内に含まれる文字セット パラメータの値を取得または設定します。 | |
MediaType | このインスタンスで表される Content-Type ヘッダー内に含まれるメディア タイプの値を取得または設定します。 | |
Name | このインスタンスで表される Content-Type ヘッダー内に含まれる名前パラメータの値を取得または設定します。 | |
Parameters | このインスタンスで表される Content-Type ヘッダー内に含まれるパラメータを格納しているディクショナリを取得します。 |
ContentType メソッド
パブリック メソッド
名前 | 説明 | |
---|---|---|
Equals | オーバーロードされます。 オーバーライドされます。 | |
GetHashCode | オーバーライドされます。 指定した ContentType オブジェクトのハッシュ コードを確認します。 | |
GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) | |
ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) | |
ToString | オーバーライドされます。 この ContentType オブジェクトの文字列形式を返します。 |
名前 | 説明 | |
---|---|---|
Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) | |
MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |
ContentType メンバ
MIME プロトコルの Content-Type ヘッダーを表します。
ContentType データ型で公開されるメンバを以下の表に示します。
パブリック コンストラクタ
パブリック プロパティ
名前 | 説明 | |
---|---|---|
Boundary | このインスタンスで表される Content-Type ヘッダー内に含まれる境界パラメータの値を取得または設定します。 | |
CharSet | このインスタンスで表される Content-Type ヘッダー内に含まれる文字セット パラメータの値を取得または設定します。 | |
MediaType | このインスタンスで表される Content-Type ヘッダー内に含まれるメディア タイプの値を取得または設定します。 | |
Name | このインスタンスで表される Content-Type ヘッダー内に含まれる名前パラメータの値を取得または設定します。 | |
Parameters | このインスタンスで表される Content-Type ヘッダー内に含まれるパラメータを格納しているディクショナリを取得します。 |
名前 | 説明 | |
---|---|---|
Equals | オーバーロードされます。 オーバーライドされます。 | |
GetHashCode | オーバーライドされます。 指定した ContentType オブジェクトのハッシュ コードを確認します。 | |
GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) | |
ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) | |
ToString | オーバーライドされます。 この ContentType オブジェクトの文字列形式を返します。 |
名前 | 説明 | |
---|---|---|
Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) | |
MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |
メディアタイプ
(Content Type から転送)
出典: フリー百科事典『ウィキペディア(Wikipedia)』 (2023/12/02 08:06 UTC 版)
メディアタイプ(日: メディア型[1],英: Media Type(s))は、ファイルやインターネット上で転送されるコンテンツの形式を表現する識別子である。MIMEタイプや要素タイプ (Content type)とも表記される。text/plainのように、スラッシュで区切る表記が特徴的である。
注釈
- ^ 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] - ^ 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] - ^ 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]
出典
- ^ a b c d e f g JIS X 5810-2:2008「多目的インターネットメール拡張 (MIME) ―第2部: メディア型」(日本産業標準調査会、経済産業省)
- ^ "Media Types". Hypertext Transfer Protocol -- HTTP/1.0 (英語). May 1996. sec. 3.6. doi:10.17487/RFC1945. RFC 1945。
- ^ “HTML 4.01 Specification” (1999年12月24日). 2017年2月2日閲覧。
- ^ 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".
- ^ “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.”
- ^ Daniel Leidert, Egon Willighagen (2007年). “The chemical-mime-data project”. 2016年10月8日時点のオリジナルよりアーカイブ。2016年4月28日閲覧。
- ^ “Chemical MIME Home page”. 2019年5月11日閲覧。
- ^ 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 .
- ^ a b c d e f g Media Type Specifications and Registration Procedures (英語). January 2013. doi:10.17487/RFC6838. RFC 6838。
- ^ Berjon, Robin (2014年5月14日). “application/x-www-form-urlencoded” (英語). IANA. 2017年3月26日閲覧。
- 1 メディアタイプとは
- 2 メディアタイプの概要
- 3 名称について
- 4 関連項目
- 5 外部リンク
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-JP、RFC 3676 で規定されるflowedおよびdelspの文字列折り返し処理を適用) text/html; charset=UTF-8(HTMLテキスト、UTF-8) multipart/alternative(HTMLメールにおいて、HTMLによるメッセージと同等のプレーンテキストによるメッセージを用意する場合のように、同じ情報を異なる形式で表したマルチパート) type毎に未知のsubtypeの扱いが規定されており、受信側は自分の扱えないsubtypeであっても最低限の取り扱いが可能となる。text の場合は text/plain、application/octet-stream、multipart の場合は multipart/mixed である。application、image、audio、videoなどは、未知のsubtypeについてapplication/octet-streamとして扱うよう規定している。
※この「Content-Type」の解説は、「Multipurpose Internet Mail Extensions」の解説の一部です。
「Content-Type」を含む「Multipurpose Internet Mail Extensions」の記事については、「Multipurpose Internet Mail Extensions」の概要を参照ください。
- Content Typeのページへのリンク