Tuesday, November 9, 2010

asp.net dynamic embedded resources

Use Case

You have an embedded css stylesheet (main.css) and background image (bg.gif). In css you would like to have smth like:

#header {
    background : #7F99BE url('reference to bg.gif') repeat-x scroll center center;
    border     : solid 1px #122A59;


First, make sure, that main.css and bg.gif are marked as Embedded Resources in property editor.
Then, make sure that they're registered to be included into assembly manifest using commands below:

[assembly: WebResource("XXX.YYY.Content.css.main.css", "text/css", PerformSubstitution=true)]
[assembly: WebResource("XXX.YYY.Content.images.bg.gif", "image/gif")]

Note, 3rd parameter PerformSubsitution=true.

Now in main.css you can use reference to bg.gif as shown below:

#header { 
    background : #7F99BE url('<%= WebResource("XXX.YYY.Content.images.bg.gif") %>') repeat-x scroll center center; 
    border     : solid 1px #122A59;

For more information, refer to excellent article about embedding resources into assembly at: 

1 comment:

  1. very interesting article i feel very enthusiastic while reading and the information
    provided in this article is so useful for me.content in this article guides in clarifying
    some of my doubts of oracle fusion financials
    thank for sharing information
    oracle fusion procurement training
    oracle fusion financials training