Content TypeParse(String) Method
Parse the specified text into a new instance of the ContentType class.
Definition
Namespace: MimeKit
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
The parsed ContentType.
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public static ContentType Parse(
string text
)Parameters
- text String
- The text.
Return Value
ContentTypeThe parsed ContentType.
Remarks
Parses a Content-Type value from the specified text.
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
}
Exceptions
| ArgumentNullException | text is . |
| ParseException | The text could not be parsed. |