Web Design Forum HTML CSS JavaScript PHP Graphic Design SEO forum
How to embed resources in ASP.NET 2.0 assemblies - Printable Version

+- Web Design Forum HTML CSS JavaScript PHP Graphic Design SEO forum (http://www.webdesignforum.com.au)
+-- Forum: Web and Graphic Design (/forumdisplay.php?fid=1)
+--- Forum: Programming (/forumdisplay.php?fid=10)
+--- Thread: How to embed resources in ASP.NET 2.0 assemblies (/showthread.php?tid=191)



How to embed resources in ASP.NET 2.0 assemblies - justinOrel - 02-04-2011 04:03 PM

Embedding the resources in an assembly


RE: How to embed resources in ASP.NET 2.0 assemblies - dianna - 08-12-2011 08:38 PM

What are these resources?
These resources could be any resources that you need for proper display, functioning, validation, and execution of the components in your project. These are vital resources that tend to and need to stay consistent across the application.


RE: How to embed resources in ASP.NET 2.0 assemblies - netshet - 08-12-2011 08:54 PM

Embedding the resources in an assembly
To do this, follow these steps:

1. Add the resource as an existing item into the project.
2. Set the resource type to be "embedded resource".


RE: How to embed resources in ASP.NET 2.0 assemblies - daipham - 10-10-2011 01:51 PM

http://support.microsoft.com/kb/910445
Hope this help


RE: How to embed resources in ASP.NET 2.0 assemblies - hairtransplant - 01-23-2012 02:45 AM

hat are the advantages of embedding them?
You could put all your dependencies into one single assembly and then ship the assembly out to whoever needs it without having to worry about stuff like does the user has the latest client-side scripts? Did the user remember to put the images in the /something/something/images folder? Did the user set the permissions for the new folder accordingly? Is there any conflict between the resources that my library requires and any other library? Well, the list could go on.
Back to the top
Embedding the resources in an assembly
To do this, follow these steps:

Add the resource as an existing item into the project.
Set the resource type to be "embedded resource".

Note This option is not available if you add the item directly to the Web site itself. Here is what you would see in such a situation:

Embedded resource


You can only apply this option on resources that are included with class libraries (assemblies in their own right). Here is what you would see:

Included with class libraries
Next, open the AssemblyInfo.cs file of that library, and then add the following line of code to it:

[assembly: WebResource("WebControlLibrary1.1.JPG", "img/jpeg")]

Add the following line of code and a reference to System.web.dll if missing:

using System.Web.UI

You need to use the namespace when you declare the resources as well as when you request the resources.
In the page (or in the control) that needs these resources, use the Page.ClientScript.GetWebResourceUrl method to get them.

For example, you might use the following methods:
To get an image that is used as an embedded resource, you use the following code example.

Image img = new Image();

img.ImageUrl = Page.ClientScript.GetWebResourceUrl(typeof(WebControlLibrary1.WebCustomControl1)​, @"WebControlLibrary1.1.JPG");


To add a style sheet to a page header, you use the following code example.

string includeTemplate ="<link rel='stylesheet' text='text/css' href='{0}' />";

string includeLocation = Page.ClientScript.GetWebResourceUrl(typeof(WebControlLibrary1.WebCustomControl1)​, "Assembly.styles.css");

LiteralControl include = new LiteralControl(String.Format(includeTemplate, includeLocation)); HtmlControls.HtmlHead) Page.Header).Controls.Add(include);


RE: How to embed resources in ASP.NET 2.0 assemblies - therapy - 02-21-2012 01:54 AM

These resources could be any resources that you need for proper display, functioning, validation, and execution of the components in your project. These are vital resources that tend to and need to stay consistent across the application.


RE: How to embed resources in ASP.NET 2.0 assemblies - kavinpeters - 08-31-2012 12:05 AM

this is very informative post thanks for sharing