ConfigurationManager.AppSettings – How to modify and save?

I know I’m late ๐Ÿ™‚ But this how i do it: public static void AddOrUpdateAppSettings(string key, string value) { try { var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var settings = configFile.AppSettings.Settings; if (settings[key] == null) { settings.Add(key, value); } else { settings[key].Value = value; } configFile.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name); } catch (ConfigurationErrorsException) { Console.WriteLine(“Error writing app settings”); } } … Read more

Why isn’t there an XML-serializable dictionary in .NET?

I know this has been answered before, but since I have a very concise way (code) for doing IDictionary serialization with the DataContractSerializer class (used by WCF, but could and should be used anywhere) I couldn’t resist contributing it here: public static class SerializationExtensions { public static string Serialize<T>(this T obj) { var serializer = … Read more

manual language selection in an iOS-App (iPhone and iPad)

In the meantime I did find a solution for my problem on myself: I created a new class “LocalizeHelper”: Header LocalizeHelper.h //LocalizeHelper.h #import <Foundation/Foundation.h> // some macros (optional, but makes life easy) // Use “LocalizedString(key)” the same way you would use “NSLocalizedString(key,comment)” #define LocalizedString(key) [[LocalizeHelper sharedLocalSystem] localizedStringForKey:(key)] // “language” can be (for american english): “en”, … Read more

Automatically set appsettings.json for dev and release environments in asp.net core?

Update for .NET Core 3.0+ You can use CreateDefaultBuilder which will automatically build and pass a configuration object to your startup class: WebHost.CreateDefaultBuilder(args).UseStartup<Startup>(); public class Startup { public Startup(IConfiguration configuration) // automatically injected { Configuration = configuration; } public IConfiguration Configuration { get; } /* … */ } CreateDefaultBuilder automatically includes the appropriate appsettings.Environment.json file … Read more

Bind to a value defined in the Settings

First, you need to add a custom XML namespace that will design the namespace where the settings are defined: xmlns:properties=”clr-namespace:TestSettings.Properties” Then, in your XAML file, access the default settings instance using the following syntax: {x:Static properties:Settings.Default} So here is the final result code: <ListBox x:Name=”lb” ItemsSource=”{Binding Source={x:Static properties:Settings.Default}, Path=Names}” /> Source: WPF – How to … Read more

Reading settings from app.config or web.config in .NET

For a sample app.config file like below: <?xml version=”1.0″ encoding=”utf-8″ ?> <configuration> <appSettings> <add key=”countoffiles” value=”7″ /> <add key=”logfilelocation” value=”abc.txt” /> </appSettings> </configuration> You read the above application settings using the code shown below: using System.Configuration; You may also need to also add a reference to System.Configuration in your project if there isn’t one already. … Read more

Opening the Settings app from another app

As mentioned by Karan Dua this is now possible in iOS8 using UIApplicationOpenSettingsURLString see Apple’s Documentation. Example: Swift 4.2 UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!) In Swift 3: UIApplication.shared.open(URL(string:UIApplicationOpenSettingsURLString)!) In Swift 2: UIApplication.sharedApplication().openURL(NSURL(string:UIApplicationOpenSettingsURLString)!) In Objective-C [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; Prior to iOS 8: You can not. As you said this has been covered many times and that pop up … Read more