Referencing Embedded resources from other resources in c#

Question :

Referencing Embedded resources from other resources in c#,

Answer :

In my web application I include all of my JavaScripts as js files that are embedded resources in the assembly, and add them to the page using ClientScriptManager.GetWebResourceUrl(). However, in some of my js files, I have references to other static assets like image urls. I would like to make those assembly resources as well. Is there a way to tokenize the reference to the resource? e.g.

this.drophint = document.createElement('img');  this.drophint.src = '';  

Could become something like:

this.drophint = document.createElement('img');  this.drophint.src = '{resource:assembly.location.dragdrophint.gif}';  


I’d suggest that you emit the web resources as a dynamic javascript associative array.

Read More  How do I use a pipe in the exec parameter for a find command?

Server side code:

StringBuilder script = new StringBuilder();  script.Append("var imgResources = {};");  script.AppendFormat("imgResources['{0}'] = '{1}';",       "drophint",       Page.ClientScript.GetWebResourceUrl(Page.GetType(), "assembly.location.dragdrophint.gif"));  script.AppendFormat("imgResources['{0}'] = '{1}';",       "anotherimg",       Page.ClientScript.GetWebResourceUrl(Page.GetType(), "assembly.location.anotherimg.gif"));    Page.ClientScript.RegisterClientScriptBlock(      Page.GetType(),      "imgResources",      script.ToString(),       true);  

Then your client side code looks like this:

this.drophint = document.createElement('img');  this.drophint.src = imgResources['drophint'];  this.anotherimg = document.createElement('img');  this.anotherimg.src = imgResources['anotherimg'];  

Hope this helps.

That’s the answer Referencing Embedded resources from other resources in c#, Hope this helps those looking for an answer. Then we suggest to do a search for the next question and find the answer only on our site.

Read More  Fast Disk Cloning

Disclaimer :

The answers provided above are only to be used to guide the learning process. The questions above are open-ended questions, meaning that many answers are not fixed as above. I hope this article can be useful, Thank you