WebResourceAttribute.WebResource Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets a string containing the name of the resource that is referenced by the WebResourceAttribute class.
public:
property System::String ^ WebResource { System::String ^ get(); };
public string WebResource { get; }
member this.WebResource : string
Public ReadOnly Property WebResource As String
Property Value
The name of the resource.
Examples
The following code example demonstrates how to query the value of the WebResource 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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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>");
}
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>WebResourceAttribute Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<AspNetSamples:MyCustomControl id="MyCustomControl1" runat="server">
</AspNetSamples:MyCustomControl>
</div>
</form>
</body>
</html>
<%@ Page Language="VB" %>
<%@ Register TagPrefix="AspNetSamples" Namespace="Samples.AspNet.VB.Controls" Assembly="Samples.AspNet.VB.Controls" %>
<%@ Import Namespace="System.Reflection" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
' Get the assembly metatdata.
Dim clsType As Type = GetType(MyCustomControl)
Dim a As Assembly = clsType.Assembly
For Each attr As Attribute In Attribute.GetCustomAttributes(a)
'Check for WebResource attributes.
If attr.GetType() Is GetType(WebResourceAttribute) Then
Dim wra As WebResourceAttribute = CType(attr, WebResourceAttribute)
Response.Write("Resource in the assembly: " & wra.WebResource.ToString() & _
" with ContentType = " & wra.ContentType.ToString() & _
" and PerformsSubstitution = " & wra.PerformSubstitution.ToString() & "</br>")
End If
Next attr
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>WebResourceAttribute Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<AspNetSamples:MyCustomControl id="MyCustomControl1" runat="server">
</AspNetSamples:MyCustomControl>
</div>
</form>
</body>
</html>
Applies to
See also
Collaborer avec nous sur GitHub
La source de ce contenu se trouve sur GitHub, où vous pouvez également créer et examiner les problèmes et les demandes de tirage. Pour plus d’informations, consultez notre guide du contributeur.