- How do I get the absolute path of files in the embedded Resource?
- 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)
Asked
Active
Viewed 48 times
-4

abatishchev
- 98,240
- 88
- 296
- 433

Jieke Wei
- 173
- 2
- 13
-
3An *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 Answers
0
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.
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
-
Thanks for the first answer. And for the second one, if I set that property, how should I write the path? – Jieke Wei Feb 09 '18 at 23:42
-
It would be good to know what type of project this is, to know in what environment you'll be accessing this image. – Stanislas Feb 09 '18 at 23:46
-
-
-