ContentType Kelas
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mewakili header Tipe-Konten protokol MIME.
public ref class ContentType
public class ContentType
type ContentType = class
Public Class ContentType
- Warisan
-
ContentType
Contoh
Contoh kode berikut mengirimkan pesan email dengan lampiran dan menampilkan ContentDisposition properti untuk lampiran.
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 email 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 email 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;
try
{
client.Send(message);
}
catch (Exception ex)
{
Console.WriteLine("Exception caught in CreateMessageWithAttachment(): {0}",
ex.ToString());
}
// 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();
}
Keterangan
Informasi di ContentType kelas digunakan untuk menjelaskan data yang terkandung dalam pesan email sedimikian baiknya sehingga perangkat lunak yang menampilkan email dapat menyajikan konten dengan cara yang sesuai. ContentType digunakan dengan Attachment kelas untuk menentukan jenis konten dalam lampiran.
Sintaks header Jenis Konten dijelaskan dalam RFC 2045 Bagian 5.1. RFC 2046 menyediakan informasi terperinci tentang jenis media MIME dan parameternya. RFC ini tersedia di https://www.ietf.org.
Konstruktor
| Nama | Deskripsi |
|---|---|
| ContentType() |
Menginisialisasi instans default baru kelas ContentType . |
| ContentType(String) |
Menginisialisasi instans ContentType baru kelas menggunakan string yang ditentukan. |
Properti
| Nama | Deskripsi |
|---|---|
| Boundary |
Mendapatkan atau mengatur nilai parameter batas yang disertakan dalam header Tipe Konten yang diwakili oleh instans ini. |
| CharSet |
Mendapatkan atau mengatur nilai parameter charset yang disertakan dalam header Content-Type yang diwakili oleh instans ini. |
| MediaType |
Mendapatkan atau mengatur nilai jenis media yang disertakan dalam header Tipe Konten yang diwakili oleh instans ini. |
| Name |
Mendapatkan atau mengatur nilai parameter nama yang disertakan dalam header Content-Type yang diwakili oleh instans ini. |
| Parameters |
Mendapatkan kamus yang berisi parameter yang disertakan dalam header Content-Type yang diwakili oleh instans ini. |
Metode
| Nama | Deskripsi |
|---|---|
| Equals(Object) |
Menentukan apakah header tipe isi dari objek yang ditentukan ContentType sama dengan header tipe isi objek ini. |
| GetHashCode() |
Menentukan kode hash objek yang ditentukan ContentType . |
| GetType() |
Mendapatkan Type instans saat ini. (Diperoleh dari Object) |
| MemberwiseClone() |
Membuat salinan dangkal dari Objectsaat ini. (Diperoleh dari Object) |
| ToString() |
Mengembalikan representasi string dari objek ini ContentType . |