I am currently programming hangman for learning purposes. For that, I have a text file with around 6000 words as an embedded resource. The programm reads the file and takes one random string out of it. Now for added complexity, I made a wordeditor, where you can write your own words. Now my question is: How can I save the edited string array to the resource file?
This code reads the resource file and displays it in a multi-line textbox.
public editorForm()
{
InitializeComponent();
string[] Lines = Properties.Resources.wordRes.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < Lines.Length; i++)
{
textBox1.Text += Lines[i] + Environment.NewLine;
}
textBox1.SelectionStart = textBox1.Text.Length;
}
And this is my current code for saving, right now its just saving the edited file to the desktop, but I want it to save it as the resource.
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
string[] words = textBox1.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
FileStream overwrite = new FileStream(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Hangman.txt", FileMode.Create);
using (StreamWriter file = new StreamWriter(overwrite))
{
for (int i = 0; i < words.Length; i++)
{
file.Write(words[i] + Environment.NewLine);
}
}
MessageBox.Show("Words saved. ");
}
The embedded resource is cannot be updated or changed after the assembly has been compiled besides something hacky.
Why dont you save the data to disk and then when you load it merge the data with the data in the embedded resource. Or just have the file on disk and get of the embedded resource or use embedded resource as default if the file doesnt exist and then write to disk.