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 から継承されます。) |
Weblioに収録されているすべての辞書からcontent_typeを検索する場合は、下記のリンクをクリックしてください。
全ての辞書からcontent_type を検索
- content_typeのページへのリンク