ContentType Property

WebResourceAttribute.ContentType Property


Gets a string containing the MIME type of the resource that is referenced by the WebResourceAttribute class.

Namespace:   System.Web.UI
Assembly:  System.Web (in System.Web.dll)

public string ContentType { get; }

Property Value

Type: System.String

The content type of the resource.

Examples of content types are "image/jpeg" and "text/xml". For more information on MIME types, go to the Internet Assigned Numbers Authority Web site and refer to the section on media types.

The following code example demonstrates how to query the value of the ContentType property.

This code example is part of a larger example provided for the WebResourceAttribute class.

<%@ Page Language="C#" %>
<%@ Register TagPrefix="AspNetSamples" Namespace="Samples.AspNet.CS.Controls" Assembly="Samples.AspNet.CS.Controls" %>
<%@ Import Namespace="System.Reflection" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<script runat="server">

  protected void Page_Load(object sender, EventArgs e)

    // Get the assembly metatdata.
    Type clsType = typeof(MyCustomControl);
    Assembly a = clsType.Assembly;

    // Iterate through the attributes for the assembly.
    foreach (Attribute attr in Attribute.GetCustomAttributes(a))
      //Check for WebResource attributes.
      if (attr.GetType() == typeof(WebResourceAttribute))
        WebResourceAttribute wra = (WebResourceAttribute)attr;
        Response.Write("Resource in the assembly: " + wra.WebResource.ToString() +
          " with ContentType = " + wra.ContentType.ToString() +
          " and PerformsSubstitution = " + wra.PerformSubstitution.ToString() + "</br>");

<html xmlns="" >
<head runat="server">
    <title>WebResourceAttribute Example</title>
    <form id="form1" runat="server">
      <AspNetSamples:MyCustomControl id="MyCustomControl1" runat="server">

.NET Framework
Available since 2.0
Return to top
© 2015 Microsoft