read this: [
^]
Quote:
String resources are always embedded and cannot be changed; file resources are always linked and cannot be changed.
A. adding a file using the Resource editor copies the
content of the file into your Project as a
static element: the file you added might change, but, your resource (resx) content will not.
B. assuming that the file has
content that changes, and, that you always want to be processing the current content:
B.1. create an embedded resource from a file:
add a new, or existing, Text file to your Project
right click on the file in the Solution Explorer, and set the Build Action for this file to 'Embedded Resource," with, usually, the "Copy if newer" setting.
B.2. to read the file contents at runtime:
// code from: [
^] by dtb
using System.IO;
using System.Reflection;
public string GetEmbeddedResource(string namespacename, string filename)
{
var assembly = Assembly.GetExecutingAssembly();
var resourceName = namespacename + "." + filename;
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
using (StreamReader reader = new StreamReader(stream))
{
string result = reader.ReadToEnd();
return result;
}
}
Sample call from actual code:
string s = GetEmbeddedResource("SociometryTree", "Notes.txt");