使用C#,如何访问资源文件(.resx)并从添加到其中的文本文件读取? [英] Using C#, How to access to a resource file (.resx) and read from a text file added to it?
问题描述
我已经在我的项目中添加了一个名为CrpResource.resx的资源文件。
然后,在将文本文件添加到资源文件之后,我想访问它并通过代码从中读取。
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.
请提出任何建议。
推荐答案
@Brij提供了答案的核心。
@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.
这篇关于使用C#,如何访问资源文件(.resx)并从添加到其中的文本文件读取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!