Can anyone please tell me how to Add resources (image, string etc) in \'Resources.resx\' dynamically.
I need to add a new bitmap to the Resources.resx from the program at ru
You can use ResourceWriter to do just that, but I wouldn't recommend writing dynamic resources to resx files. Instead I would use some kind of database (i.e. embedded one).
EDIT on invalid answer
I am sorry, I wasn't precise. My suggestion tells you how to create compiled resource file (the one with .resources extension), not original .resx file. The code below works in terms, that it is able to write image (as System.Drawing) to a file named my.resources. You could surely read one out with ResourceReader:
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
Bitmap bitmap = new Bitmap(openFileDialog1.FileName);
IResourceWriter writer = new ResourceWriter("my.resources");
writer.AddResource("myImage", bitmap);
writer.Close();
}
It seems that you need to do Close()
instead of Generate()
. I think that by closing resource stream you force it to be written to disk.
You can make sure that it is there by previewing the file (my.resources, that is) with some hex editor.