change embedded resource file during runtime

人走茶凉 提交于 2019-12-03 17:27:31

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.

Pranay Rana

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!