App Settings Problem

I need to make the Application settings portable, or the file location the same as the program startup path, i know .net stores the settings in a user folder, but my application is a usb portable app.

I am wondering how can i save/get settings from a file. I notice myapp.exe.config is in the program directory, but this is for read only default values.

So how can i edit that file, i can just use that file for settings.

When the settings change i want my application to use the new setting values without my app restarting is that possible



Answer this question

App Settings Problem

  • S_J

    I think i have provided a work around, anyone can simply modify it for their needs, This will change the settings in an instant. and forms reflect changes.

    Anyone have a better idea

    using (StreamWriter sw = new System.IO.StreamWriter(Application.StartupPath+@"\Pipeline.exe.config"))
    {
    sw.WriteLine(@"< xml version=""1.0"" encoding=""utf-8"" >");
    sw.WriteLine("<configuration>");
    sw.WriteLine(" <configSections>");
    sw.WriteLine(@" <sectionGroup name=""userSettings"" type=""System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"" >");
    sw.WriteLine(@" <section name=""Pipeline.Properties.Settings"" type=""System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"" allowExeDefinition=""MachineToLocalUser"" requirePermission=""false"" />");
    sw.WriteLine(" </sectionGroup>");
    sw.WriteLine(" </configSections>");
    sw.WriteLine(" <userSettings>");
    sw.WriteLine(" <Pipeline.Properties.Settings>");
    sw.WriteLine(@" <setting name=""lastbackup"" serializeAs=""String"">");
    sw.WriteLine(@" <value>"+passedlastbackup+"</value>");
    sw.WriteLine(@" </setting>");
    sw.WriteLine(@" <setting name=""usbfolder"" serializeAs=""String"">");
    sw.WriteLine(@" <value>"+passedUSBFolder+"</value>");
    sw.WriteLine(@" </setting>");
    sw.WriteLine(@" <setting name=""hfolder"" serializeAs=""String"">");
    sw.WriteLine(@" <value>"+passedHFolder+"</value>");
    sw.WriteLine(@" </setting>");
    sw.WriteLine(@" <setting name=""SmartSync"" serializeAs=""String"">");
    sw.WriteLine(@" <value>"+ passedSS+"</value>");
    sw.WriteLine(@" </setting>");
    sw.WriteLine(@" <setting name=""SmartDeletion"" serializeAs=""String"">");
    sw.WriteLine(@" <value>" + passedSD + "</value>");
    sw.WriteLine(@" </setting>");
    sw.WriteLine(@" </Pipeline.Properties.Settings>");
    sw.WriteLine(@" </userSettings>");
    sw.WriteLine(@"</configuration>");
    }


  • App Settings Problem