You may've heared about new ASP.NET 2.0 System.Web.UI.WebResourceAttribute class. It defines the metadata attribute that enables an embedded resource in an assembly. It is valid only when used on assembly declarations and it is used to enable a specified embedded resource in an assembly for use as a Web resource.
Where you would store these files "resources"?! The answer is you can embed them in your assembly and reference them as web resources from your code.
To register a resource as WebResource you would use this line of code, you can do that in AssemblyInfo file:
[assembly: System.Web.UI.WebResource("dropdownarrow.jpg", "image/jpeg")]
And you can reference your resource using ClientScriptManager class through Page.ClientScript Property as the following
string resUrl = this.Page.ClientScript.GetWebResourceUrl(typeof(YouControlType), "dropdownarrow.jpg");
Now use your resUrl to display your image!....
BUT WAIT, this is not going to work!!
If you followed the MSDN code while you are VS.NET this is not going to work at all, your image or your resource file never appear.
Here are the Rule:
- You should know your Assembly default namespace.
- Recognize where exactly your resource file located in your project, "Its Path"
- Define the correct resource name.
Suppose your default namespace is DotNetSlackers.WebControls, while your resource file name is DotNetSlackersUtil.js, this file is located on a folder named DNSResources/Scripts in your project -Dont care about your project name or assembly name, just focus on your Default namespace name-.
Now your resource file should be name "DotNetSlackers.WebControls.DNSResources.Scripts.DotNetSlackersUtil.js".
The rule simpley is [Default namespace].[Resource Path from the project root -replace '/' with '.' of course-].[Resource FileName]
So you'll register your WebResource as the following:
And you can get your resource URL as the following:
string resUrl = this.Page.ClientScript.GetWebResourceUrl(typeof(YouControlType), "DotNetSlackers.WebControls.DNSResources.Scripts.DotNetSlackersUtil.js");
Hope this would help somebody