Search code examples
c#asp.net.netresources

How To Get the images filename which that stored in resource file .resx


I needed a way to store images, so I found the best way is to create a resource file and store them in it, however I choose the option {Link at Compile Time} so it creates a resource folder in the project, but when I call for an image it returns Bitmap Image file instead of the image URL or filename or image path, I need it this way because I'm developing a web API so I don't want to send an image but I want instead to send its URL/path so is there a way to get image URL/path from resource file since it's already there. Here is an image explain where it is in resource file:

enter image description here


Solution

  • The compiled code has the resource (the image in your case) itself embedded. The file path of the resource is evaluated at compile time but is not included in the compiled code.

    Unless you are using a convention like resource name = image file name, you cannot get its path.

    It is the very purpose of resources to make you independent of files.


    You should probably include the image name or image url as string resource instead of the image itself.

    Use "Add New String" instead of "Add Existing File...".


    See also SO question: ASP.NET Get physical filepath from URL