Skip to main content
HttpContentHeaderCollection.ContentType | contentType property

Applies to Windows and Windows Phone

Gets or sets the HttpMediaTypeHeaderValue object that represent the value of an HTTP Content-Type header on the HTTP content.


var contentType = httpContentHeaderCollection.contentType;
httpContentHeaderCollection.contentType = contentType;

public HttpMediaTypeHeaderValue ContentType { get; set; }

Public Property ContentType As HttpMediaTypeHeaderValue

property HttpMediaTypeHeaderValue^ ContentType { 
   HttpMediaTypeHeaderValue^ get();
   void set (HttpMediaTypeHeaderValue^ value);

Property value

Type: HttpMediaTypeHeaderValue

The object that represent the value of an HTTP Content-Type header on the HTTP content. A null value means that the header is absent.


The ContentType property represents the Content-Type header value on HTTP content. The Content-Type header is the MIME type of the content.

The following sample code shows a method to get or set the Content-Type header value on HTTP content using the ContentType property on the HttpContentHeaderCollection object.

    // Content-Type header
    // HttpMediaTypeHeaderValue (MediaType, Charset are strings, Parameters is an IList<HttpNameValueHeaderValue>)
    void DemoContentType(IHttpContent content) {
        var h = content.Headers;
        h.ContentType = new HttpMediaTypeHeaderValue("myMediaType");

        var header = h.ContentType;
        uiLog.Text += "\nCONTENT TYPE HEADER\n";

        // Parameters is an IList<HttpNameValueHeaderValue> of Name/Value strings
        var parameterString = "";
        foreach (var parameter in header.Parameters) {
                parameterString += string.Format("[{0}={1}] ", parameter.Name, parameter.Value);
        if (parameterString == "") {
                parameterString = "(no parameters)";

        uiLog.Text += string.Format("Content-Type: MediaType: {0} CharSet: {1} Parameters: {2} ToString: {3}\n", header.MediaType, header.CharSet, parameterString, header.ToString());


Minimum supported client

Windows 8.1

Minimum supported server

Windows Server 2012 R2

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]


Windows::Web::Http::Headers [C++]



See also