我的项目附有几个.txt文件(参见How to embed a text file in a .NET assembly?)。
如何获取这些文件的列表?我想写一些像这样的代码:
foreach (string textfile in thisprogram.Resources.TextFiles) {
if (textfile.Contains(x)) { /* etc. */ }
}
答案 0 :(得分:4)
您是否尝试根据“System.String”类型或“TextFile1”名称确定它是否为文本文件?我不确定是否有一种方法可以根据它是一个文本文件的事实来做到这一点。这将显示所有字符串资源(文本文件和字符串资源),这有效吗?:
using System.Collections;
using System.Resources;
using System.Globalization;
ResourceSet resourceSet = Properties.Resources.ResourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true);
foreach (DictionaryEntry entry in resourceSet)
{
if (entry.Value is string)
{
if (entry.Value.ToString().Contains(x)) { /* etc. */ }
}
}