I have a written a program that uses a resource (embedded TEXT file) for the programs default configuration. i want to be able to allow users to change this default behavior. i would like to know how to modify the embedded resource file so that following times program is used it would use the modified version.
appreciate the help
I think what you are looking for is a settings
file.
The embedded resources are compiled into your exe/dll and are not meant to be modified.
here is one way to update file which is embedded in the project , here is an example of xml file. You can change it to txt file as per your need
string path = Path.Combine(
Environment.GetFolderPath(
Environment.SpecialFolder.ApplicationData),
Application.CompanyName);
path = Path.Combine(path, Application.ProductName);
path = Path.Combine(path, subFolder);
path = Path.Combine(path, "fileName.xml");
if(!File.Exists(path)){
Assembly thisAssembly = Assembly.GetExecutingAssembly();
Stream rgbxml = thisAssembly.GetManifestResourceStream(
"YourNamespace.fileName.xml");
XmlDocument doc = new XmlDocument();
doc.Load(rgbxml);
doc.PreserveWhitespace = true;
doc.Save(path);
check full article : SAVING AN EMBEDDED RESOURCE XML FILE AT RUNTIME IN C#
you better try using Properties to save settings , Example: Properties.Settings.Default
To add properties , in solution explorer right click ->Properties->Settings(Tab)
Then Add whatever you need , then in code access from .Default
To save your updates settings in runtime use the following: Properties.Settings.Default.Save()
Hope this helps
来源:https://stackoverflow.com/questions/13174425/change-embedded-resource-file-during-runtime