Change the embedded resource file at runtime

I have a written program that uses a resource (embedded TEXT file) for the default configuration for programs. I want users to be able to change this default behavior. I would like to know how to modify the embedded resource file so that next time a program is used that uses a modified version.

appreciate the help

+4
source share
3 answers

I think you are looking for a settings file. The attached resources are compiled into your exe / dll and are not intended to be modified.

+4
source

here is one way to update the file that is built into the project, here is an example xml file. You can change it to a txt file according to your needs.

 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 out the full article: SAVING EMBEDDED RESOURCE XML TO RUNTIME IN C #

+2
source

try using properties to save the settings, for example: Properties.Settings.Default

To add properties, right-click → Properties-> Settings (tab)

Then add everything you need, then to access the code from .Default

To save update settings at runtime, follow these steps: Properties.Settings.Default.Save ()

Hope this helps

0
source

Source: https://habr.com/ru/post/1443400/


All Articles