开发者

Using C#, How to access to a resource file (.resx) and read from a text file added to it?

开发者 https://www.devze.com 2022-12-16 01:28 出处:网络
I\'ve added a resource file to my开发者_如何学运维 project called CrpResource.resx . Then, after adding a text file to the resource file, I wanna to access to it and read from it by code.

I've added a resource file to my开发者_如何学运维 project called CrpResource.resx . Then, after adding a text file to the resource file, I wanna to access to it and read from it by code.

any suggestion please.


@Brij has provided the core of the answer.

However, the difficult bit here is knowing what the resource name is - it's not always easy after embedding a file as a resource to work out its fully qualified name.

An easy way to find out is to add this line temporarily to your code:

string[] names = Assembly.GetExecutingAssembly().GetManifestResourceNames();

Then run the program, and you can view the 'names' list of all available resources in the debugger.


 _assembly = Assembly.GetExecutingAssembly();
 _textStreamReader = new StreamReader(_assembly.GetManifestResourceStream("MyNamespace.MyTextFile.txt"));

See following:
http://support.microsoft.com/kb/319292

0

精彩评论

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

关注公众号