2013-03-06 115 views
2

我有幾個.txt文件附加到我的項目中(請參閱How to embed a text file in a .NET assembly?)。獲取資源文本文件列表

如何獲得這些文件的列表?我想寫出像這樣的代碼:

foreach (string textfile in thisprogram.Resources.TextFiles) { 
     if (textfile.Contains(x)) { /* etc. */ } 
} 
+0

重複http://stackoverflow.com/questions/8208289/list-all-embedded-resources-in-a的-夾? – 2013-03-06 18:20:29

回答

2

你們是不是要確定它是基於「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. */ } 
    } 
} 
+1

如何訪問「ResourceSet」類型?有我需要的'使用'嗎? – Joe 2013-03-06 18:26:33

+0

是的,我剛剛使用usings更新了我的帖子。 – 2013-03-06 18:27:49