embedded resource

  • Thread starter Thread starter Andreas Zita
  • Start date Start date
A

Andreas Zita

Hi

Im creating my first 2.0 site and I cant find the Build Action property? I
want to embedd an image-file in my site-assembly but I don't know how? In
1.1 I could set Build Action to Embedded Resource in the properties pane but
this doesn't seem to be available any more???

/Andreas
 
Hi,

ASP.NET does not build assemblies with resources exaclty similarly as it did
in ASP.NET 1.1 (unless you start to use web application projects see
http://webproject.scottgu.com)

Now, you'd add a resource file to App_GlobalResources directory (special
directory for ASP.NET 2.0) and add the image as a resource to that resource
file.
 
Aha I see... interresting. Previously I used to embedd layout images/icons
and retrieve them with a custom aspx-request and a resource-id such as:
..../GetResource.aspx?id=HeaderBackground. Im building my html-pages with XSL
(HTMLWriter to Response.Output) so I need URL:s to my resources. Is there a
similar built in method to retrieve resources that have been embedded in a
resx-file in 2.0?

/Andreas
 
I don't know what you mean but:

1) Create the folder as suggested.
2) Add a textfile like text1.txt (for testing)
3) Add the resource.resx
4) The pane is shown, drag the text1.text on this resource pane.
5) You should see a pretty large image with title.
6) In your source use: ... resources.resource.text1.tostring

That's it.
 
Okey ... Anyhow ... Is this right?: xsl-files in App_GlobalResources always
embeds but in App_LocalResource they don't?
And ... how do I retrieve an embedded Stylesheet from App_GlobalResources ?

Thanks for your help! :)

/Andreas
 
Hi and thanks for replying ... but I still dont understand... for instance
in the second url they where pointing to the Build Action property which
isnt available anymore (?) ...

I am aware of that it isnt easy to understand what my problem really is... i
dont know for sure myself ... anyhow ... This is what I have come up with:

I have placed all my image-files in the App_GlobalResources-folder and added
them to a Images.resx file in the same folder. Then I created a aspx-file
for retrieving these images as the code below shows. Is this approach sane?
or is there some other more common method I have missed?

public partial class ASP_GetResource : System.Web.UI.Pag
{
protected void Page_Load(object sender, EventArgs e)
{
System.Drawing.Bitmap image = GetGlobalResourceObject("Images",
ResourceKey) as System.Drawing.Bitmap;
Response.ContentType = "image/gif";
image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
image.Dispose();
}

string ResourceKey { get { return Request.QueryString["res"]; }}
}

/Andreas
 
in the second url they where pointing to the Build Action property which
isnt available anymore (?) ...

It is, if you built components into external class library. Writing a class
library is still there (though not with VWD express).That example just point
to such.
I am aware of that it isnt easy to understand what my problem really is...
i dont know for sure myself ... anyhow ... This is what I have come up
with:

I have placed all my image-files in the App_GlobalResources-folder and
added them to a Images.resx file in the same folder. Then I created a
aspx-file for retrieving these images as the code below shows. Is this
approach sane? or is there some other more common method I have missed?

That works fine. There's also the Web resource mechanism, in which Page
framework provides you the URl to the resource automatically, e-g
autogenerates it so that resource is served from resource files on the fly.

For example you'd just give:

Image1.ImageUrl =
Page.ClientScript.GetWebResourceUrl(this.GetType(),"myimage.gif")
 
Just to add that web resource scenario would require the external class
library.

Teemu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top