开发者

How to get the path of an embebbed resource?

开发者 https://www.devze.com 2023-03-25 17:07 出处:网络
I included an embebbed resou开发者_Go百科rce in my C# project; I know its name and how to refer to it, so I was wondering if there is any way to get its absolute path...is there?Embedded resource is e

I included an embebbed resou开发者_Go百科rce in my C# project; I know its name and how to refer to it, so I was wondering if there is any way to get its absolute path...is there?


Embedded resource is exactly that: embedded. It means, that it's included in the assembly and does not exist as a physical file after compilation (if that's what you're looking for).


Like others have said, an embedded resource is embedded within the compiled assembly and does not exist on the file system; if you're looking to have the file on the file system you should change the build action to 'None' and the Copy to Output Directory to one of the copy values.

If however you do mean to embed the resource then it can be accessed by using the GetManifestResourceStream method of the Assembly class as follows:

GetType().Assembly.GetManifestResourceStream("someresourcestringhere")

(The above code assumes you are accessing the resource from a class within the same assembly).

The embedded resource normally follows the following format and this is the string you would pass in to the GetManifestResourceStream method:

default project namespace.folder name (if any).file name

Any spaces in folder names are replaced with an underscore, any spaces in file names are preserved.

Personally I have found the easiest way to get this string is to use a decompiler tool (such as Telerik's Just Decompile) to have a look inside the assembly and get the full resource name for the file you're looking for.


System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames();
0

精彩评论

暂无评论...
验证码 换一张
取 消