Good god was this a pain to figure out. Mainly because I read one article that seemed to have all the answers yet it didn't go into detail. So in an effort to ease my future pain and anyone else that finds this page before someone else actually documents this better...here goes:
To include a embedded resource, that has a namespace, and is located in a folder other than the root directory, do the following.
1) In your AssemblyInfo.cs file you'll need to add:
[assembly: System.Web.UI.WebResource("<Namespace>.<FolderName>.<FileName>.gif", "img/gif")]
[assembly: System.Web.UI.WebResource("<Namespace>.<FolderName>.<FileName>.js", "text/js")]
[assembly: System.Web.UI.WebResource("<Namespace>.<FolderName>.<FileName>.css", "text/css")]
For each file type.
I created some Util helper methods (place these where ya want)
private void AddStyleSheet(
string styleSheet)
{
string includeTemplate = "<link rel='stylesheet' text='text/css' href='{0}' />";
string includeLocation = Page.ClientScript.GetWebResourceUrl(this.GetType(), styleSheet);
LiteralControl include = new LiteralControl(String.Format(includeTemplate, includeLocation));
((System.Web.UI.HtmlControls.HtmlHead)Page.Header).Controls.Add(include);
}
private void AddJavaScript(string script)
{
string scriptLocation = Page.ClientScript.GetWebResourceUrl(this.GetType(), script);
Page.ClientScript.RegisterClientScriptInclude(script, scriptLocation);
}
Now to include them:
this.AddStyleSheet(
"<Namespace>.<FolderName>.<FileName>.css");
this.AddJavaScript("<Namespace>.<FolderName>.<FileName>.js");
or for an image:
image.ImageUrl = Page.ClientScript.GetWebResourceUrl(this.GetType(), "<Namespace>.<FolderName>.<FileName>.gif");
There, wasn't that intuitive? If this doesn't work, fire up reflector and look at the resources (Thanks Bill!). This will be better than blindly guessing.