Introduction
It's really easy to do:
string GetResourceFile(string assemblyPath, string nameSpace, string fileName)
{
Assembly assembly = Assembly.LoadFrom(assemblyPath);
string resourceName = nameSpace + "." + fileName;
string resource = null;
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
{
using (StreamReader reader = new StreamReader(stream))
{
resource = reader.ReadToEnd();
}
}
return resource;
}
Using the Code
Simple! Assuming MyAssembly
has a folder "Resources", containing a folder "TextFiles", containing an embedded resource text file "RevisionHistory.txt" (which it does):
GetResourceFile(@"D:\Testing\MyAssembly.dll", "MyAssembly.Resources.TextFiles", "RevisionHistory.txt");
Will return the entire text.
History
Born at an early age, he grew older. At the same time, his hair grew longer, and was tied up behind his head.
Has problems spelling the word "the".
Invented the portable cat-flap.
Currently, has not died yet. Or has he?