Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MessageBox.Show(Properties.Settings.Default.MySetting);
- Properties.Settings.Default.MySetting = "Foo";
- Properties.Settings.Default.Save();
- MessageBox.Show(Properties.Settings.Default.MySetting);
- <appSettings file="user.config">
- <add key="foo" value="some value unchanged by setup"/>
- </appSettings>
- using System.Collections.Generic;
- using System.Text;
- using System.Xml;
- namespace Utils
- {
- public class ConfigGenerator
- {
- public static void WriteExternalAppConfig(string configFilePath, IDictionary<string, string> userConfiguration)
- {
- using (XmlTextWriter xw = new XmlTextWriter(configFilePath, Encoding.UTF8))
- {
- xw.Formatting = Formatting.Indented;
- xw.Indentation = 4;
- xw.WriteStartDocument();
- xw.WriteStartElement("appSettings");
- foreach (KeyValuePair<string, string> pair in userConfiguration)
- {
- xw.WriteStartElement("add");
- xw.WriteAttributeString("key", pair.Key);
- xw.WriteAttributeString("value", pair.Value);
- xw.WriteEndElement();
- }
- xw.WriteEndElement();
- xw.WriteEndDocument();
- }
- }
- }
- }
- string configFilePath = string.Format("{0}{1}User.config", targetDir, Path.DirectorySeparatorChar);
- IDictionary<string, string> userConfiguration = new Dictionary<string, string>();
- userConfiguration["Server"] = Context.Parameters["Server"];
- userConfiguration["Port"] = Context.Parameters["Port"];
- ConfigGenerator.WriteExternalAppConfig(configFilePath, userConfiguration);
Add Comment
Please, Sign In to add comment