I have a binary file that holds a Dictionary object. I can access the data with the following code.
var result = new Dictionary<string, string>();
using (FileStream fs1 = File.OpenRead("C:\\MyDictionary.bin"))
{
using (BinaryReader br = new BinaryReader(fs1))
{
int count = br.ReadInt32();
for (int i = 0; i < count; i++)
{
string key = br.ReadString();
string value = br.ReadString();
result[key] = value;
}
}
}
I would prefer to include this binary file within my application and not refer to an external file at run time. How do I do the same thing from an embedded binary file?
I found the following code in another thread but am struggling to understand how I can get it to work with the above data.
var assembly = Assembly.GetExecutingAssembly();
var resourceName = "MyProgram.Resources.MyDictionary.bin";
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
using (StreamReader reader = new StreamReader(stream))
{
string result = reader.ReadToEnd();
}