0

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.

4

2 回答 2

2

@Brij 提供了答案的核心。

然而,这里的难点在于知道资源名称是什么——在将文件作为资源嵌入后计算出它的完全限定名称并不总是那么容易。

一个简单的查找方法是将此行临时添加到您的代码中:

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

然后运行程序,您可以在调试器中查看所有可用资源的“名称”列表。

于 2010-01-09T08:35:10.173 回答
1
 _assembly = Assembly.GetExecutingAssembly();
 _textStreamReader = new StreamReader(_assembly.GetManifestResourceStream("MyNamespace.MyTextFile.txt"));

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

于 2010-01-09T08:22:45.500 回答