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 クラス


このページでは「.NET Framework クラス ライブラリ リファレンス」からcontent_typeを検索した結果を表示しています。
Weblioに収録されているすべての辞書からcontent_typeを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からcontent_type を検索

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

辞書ショートカット

すべての辞書の索引

「content_type」の関連用語

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

   

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



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

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

©2024 GRAS Group, Inc.RSS