Say I have an exe added into my resources folder. Now how can I get the name (or even the fullpath from which its linked so that I can still have the file name) of the resource as string?
From Properties.Resources.myApp
how do I get the string "myApp"
. ToString() doesnt work. If it is important to embed the file to get the name, I can.
Edit: My question is not specifically to get the name of exe resource. But that one generic approach which gives me the name of the resource! For instance what if my resource is a bitmap image? I need to print "Lily" from Properties.Resources.Lily
. How to achieve this? ToString wont work anyways.
When you embed some file in your project resources it will be embed in your executable file when build your project so it's not exist separately from your project executable, it's not exists on your hard drive. so if you want this myApp.exe in your project folder put it in the project folder then go
Now if you want the path of myApp.exe use :
Update You should hard code "myApp" because if you go to definition of :
you will see :
It's hard coded !!!!
With
System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames();
you get a list of all ressources in your project.Now if you want to search for all exe files (I guess you have only one embedded) use the following snippet to get your assembly name.
The string format is
"YourProgram.YourAssemblyName.exe"
so just remove the first part of that string and you have your embedded ressource filename.Edit: Why don't you enumerate through your ressources and strip the leading namespace + trailing file extensions?
Edit:
To get a ressource by name, use
var prop = Properties.Resources.ResourceManager.GetObject("YourRessourceNameWithoutExtension");
It's quite easy using Linq Expressions:
s
shoud beLily
Do you mean you want to have the assembly? Here a little code snippet that get´s you all exe-files from a directory:
I know this is very old, but the accepted answer is no longer necessarily the best answer. As of C# 6.0 you can just use
nameof(...)
:Much simpler!