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

女生的网名这么多〃 提交于 2020-01-07 05:09:05

问题


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.


回答1:


@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.




回答2:


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

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



来源:https://stackoverflow.com/questions/2032795/using-c-how-to-access-to-a-resource-file-resx-and-read-from-a-text-file-add

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!