In my solution a had a folder with a few files. All this files have the Build Action "Embedded Resource".
With this code I can get a file:
assembly.GetManifestResourceStream(assembly.GetName().Name + ".Folder.File.txt");
But is there any way to get all *.txt
files in this folder? A list of names or a method to iterate through them all?
Assembly. GetManifestResourceNames Method (System.
Embedded resource has no predefined structure: it is just a named blob of bytes. So called “. resx” file is a special kind of embedded resource. It is a string -to-object dictionary that maps a name to an object. The object may be a string , an image, an icon, or a blob of bytes.
Open Solution Explorer add files you want to embed. Right click on the files then click on Properties . In Properties window and change Build Action to Embedded Resource . After that you should write the embedded resources to file in order to be able to run it.
You could check out
assembly.GetManifestResourceNames()
which returns an array of strings of all the resources contained. You could then filter that list to find all your *.txt
files stored as embedded resources.
See MSDN docs for GetManifestResourceNames
for details.
Try this, returns an array with all .txt files inside Folder directory.
private string[] GetAllTxt() { var executingAssembly = Assembly.GetExecutingAssembly(); string folderName = string.Format("{0}.Resources.Folder", executingAssembly.GetName().Name); return executingAssembly .GetManifestResourceNames() .Where(r => r.StartsWith(folderName) && r.EndsWith(".txt")) //.Select(r => r.Substring(folderName.Length + 1)) .ToArray(); }
NOTE: Uncomment the //.Select(...
line in order to get the filename.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With