-4
  1. How do I get the absolute path of files in the embedded Resource?
  2. If I store my images in a folder and use an absolute path to access them, I cannot find them after I build the solution, right?(because the built solution does not have the environment with its development environment)
abatishchev
  • 98,240
  • 88
  • 296
  • 433
Jieke Wei
  • 173
  • 2
  • 13
  • 3
    An *embedded* resource is embedded in the app exe which is why they are referred to as *embedded*. – Ňɏssa Pøngjǣrdenlarp Feb 09 '18 at 23:05
  • You should come here for questions after you've tried something and are stuck. For example, your second question should read something like: *"I've stored images in a folder and am trying to access them through code using an absolute path, but am unable to find them. How can I access the file system to get the images I have stored? Here's my code: `// some code here`."* – Rufus L Feb 09 '18 at 23:08
  • @RufusL it is not. That one is about the "resources" in the entire project. but I am asking about the file in the resources. – Jieke Wei Feb 09 '18 at 23:39
  • @RufusL actually, I tried many ways from internet, but they are not working for me. – Jieke Wei Feb 09 '18 at 23:40

1 Answers1

0
  1. A file inside an embedded resource doesn't really have an absolute path, since it's contained within your application. I assume you're looking for a way to access these files, this might be useful.

  2. You could modify the "Copy to output directory"-property of your images to have them copied to the bin-folder, but this may not be what you want. Then you could use Reflection to get access to the file, though I'm not sure if this is the most efficient way:

var executingAssemblyPath = Assembly.GetExecutingAssembly().Location;
var directory = Path.GetDirectoryName(executingAssemblyPath);
var imagePath = Path.Combine(directory, "image.gif");

There are 2 alternatives to Assembly.GetExecutingAssembly, which might be more robust depending on your deployment environment:

Stanislas
  • 1,893
  • 1
  • 11
  • 26