3

I have several .txt files attached to my project (see How to embed a text file in a .NET assembly?).

How can I get a list of these files? I'd like to write some code like this:

 foreach (string textfile in thisprogram.Resources.TextFiles) {
      if (textfile.Contains(x)) { /* etc. */ }
 }
Community
  • 1
  • 1
Joe
  • 3,804
  • 7
  • 35
  • 55

1 Answers1

4

Are you trying to determine if it's a text file based on the Type of 'System.String' or the name being "TextFile1"? I'm not sure if there's exactly a way to do it based on the fact that it's a text file. This will show all string resources (Text File and String resources), does that work?:

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. */ }
    }
}
Adam Plocher
  • 13,994
  • 6
  • 46
  • 79