ContentType Class

A class representing a Content-Type header value.

Definition

Namespace: MimeKit
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public class ContentType
Inheritance
Object    ContentType

Remarks

The Content-Type header is a way for the originating client to suggest to the receiving client the mime-type of the content and, depending on that mime-type, presentation options such as charset.

Example

C#
                    public static void ParseContentType ()
{
    // Parse() throws a ParseException if the text cannot be parsed.
    var contentType = ContentType.Parse ("text/plain; charset=\"iso-8859-1\"; format=flowed");

    Console.WriteLine ("MimeType: {0}", contentType.MimeType);         // text/plain
    Console.WriteLine ("MediaType: {0}", contentType.MediaType);       // text
    Console.WriteLine ("MediaSubtype: {0}", contentType.MediaSubtype); // plain
    Console.WriteLine ("Charset: {0}", contentType.Charset);           // iso-8859-1
    Console.WriteLine ("Format: {0}", contentType.Format);             // flowed

    // TryParse() can be used instead when the value comes from an untrusted source.
    if (ContentType.TryParse ("application/octet-stream; name=\"data.bin\"", out var type))
        Console.WriteLine ("Name: {0}", type.Name);                    // data.bin
}
                  

Constructors

ContentType Initialize a new instance of the ContentType class.

Properties

Boundary Get or set the boundary parameter.
Charset Get or set the charset parameter.
CharsetEncoding Get or set the charset parameter as an Encoding.
Format Get or set the format parameter.
MediaSubtype Get or set the media subtype.
MediaType Get or set the type of the media.
MimeType Get the simple mime-type.
Name Get or set the name parameter.
Parameters Get the list of parameters on the ContentType.

Methods

Clone Clone the content type.
Equals Determines whether the specified object is equal to the current object.
(Inherited from Object)
Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)
GetHashCode Serves as the default hash function.
(Inherited from Object)
GetType Gets the Type of the current instance.
(Inherited from Object)
IsMimeType Check if this instance of ContentType matches the specified MIME media type and subtype.
MemberwiseClone Creates a shallow copy of the current Object.
(Inherited from Object)
Parse(Byte) Parse the specified input buffer into a new instance of the ContentType class.
Parse(String) Parse the specified text into a new instance of the ContentType class.
Parse(Byte, Int32) Parse the specified input buffer into a new instance of the ContentType class.
Parse(ParserOptions, Byte) Parse the specified input buffer into a new instance of the ContentType class.
Parse(ParserOptions, String) Parse the specified text into a new instance of the ContentType class.
Parse(Byte, Int32, Int32) Parse the specified input buffer into a new instance of the ContentType class.
Parse(ParserOptions, Byte, Int32) Parse the specified input buffer into a new instance of the ContentType class.
Parse(ParserOptions, Byte, Int32, Int32) Parse the specified input buffer into a new instance of the ContentType class.
ToString Serialize the ContentType to a string.
(Overrides ObjectToString)
ToString(Boolean) Serialize the ContentType to a string, optionally encoding the parameters.
ToString(Encoding, Boolean) Serialize the ContentType to a string, optionally encoding the parameters.
ToString(FormatOptions, Encoding, Boolean) Serialize the ContentType to a string, optionally encoding the parameters.
TryParse(Byte, ContentType) Try to parse the given input buffer into a new ContentType instance.
TryParse(String, ContentType) Try to parse the given text into a new ContentType instance.
TryParse(Byte, Int32, ContentType) Try to parse the given input buffer into a new ContentType instance.
TryParse(ParserOptions, Byte, ContentType) Try to parse the given input buffer into a new ContentType instance.
TryParse(ParserOptions, String, ContentType) Try to parse the given text into a new ContentType instance.
TryParse(Byte, Int32, Int32, ContentType) Try to parse the given input buffer into a new ContentType instance.
TryParse(ParserOptions, Byte, Int32, ContentType) Try to parse the given input buffer into a new ContentType instance.
TryParse(ParserOptions, Byte, Int32, Int32, ContentType) Try to parse the given input buffer into a new ContentType instance.

See Also

Reference