settings.settings

How do I store an array of a particular type into my settings file?

浪子不回头ぞ 提交于 2019-12-04 17:07:51
For some reason, I can't seem to store an array of my class into the settings. Here's the code: var newLink = new Link(); Properties.Settings.Default.Links = new ArrayList(); Properties.Settings.Default.Links.Add(newLink); Properties.Settings.Default.Save(); In my Settings.Designer.cs I specified the field to be an array list: [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] public global::System.Collections.ArrayList Links { get { return ((global::System.Collections.ArrayList)(this["Links"])); } set { this["Links"] = value

Store String Array with Values in Application Settings [duplicate]

十年热恋 提交于 2019-12-04 16:23:58
问题 This question already has answers here : How to save a List<string> on Settings.Default? (3 answers) Closed 3 years ago . I've modified my Settings.settings file in order to have system_Filters be a System.String[] . I would like to populate this variable within the Visual Studio designer and not from within the code. I can get it to work within the code using the following: Properties.Settings.Default.system_Filters = new string[] { "a", "b", "c" }; string _systemFilters = Properties

C#: How to make sure a settings variable exists before attempting to use it from another assembly?

会有一股神秘感。 提交于 2019-12-03 17:50:18
问题 I have the following: using CommonSettings = MyProject.Commons.Settings; public class Foo { public static void DoSomething(string str) { //How do I make sure that the setting exists first? object setting = CommonSettings.Default[str]; DoSomethingElse(setting); } } 回答1: Depending on what type CommomSettings.Default is, a simple null check should be fine: if(setting != null) DoSomethingElse(setting); If you want to check BEFORE trying to retrieve the setting, you need to post the Type of

Store String Array with Values in Application Settings [duplicate]

泄露秘密 提交于 2019-12-03 10:18:53
This question already has an answer here: How to save a List<string> on Settings.Default? 3 answers I've modified my Settings.settings file in order to have system_Filters be a System.String[] . I would like to populate this variable within the Visual Studio designer and not from within the code. I can get it to work within the code using the following: Properties.Settings.Default.system_Filters = new string[] { "a", "b", "c" }; string _systemFilters = Properties.Settings.Default.system_Filters; This works correctly. However, I don't have a nice place to put this in my code and ideally want to

C#: How to make sure a settings variable exists before attempting to use it from another assembly?

戏子无情 提交于 2019-12-03 05:53:34
I have the following: using CommonSettings = MyProject.Commons.Settings; public class Foo { public static void DoSomething(string str) { //How do I make sure that the setting exists first? object setting = CommonSettings.Default[str]; DoSomethingElse(setting); } } Depending on what type CommomSettings.Default is, a simple null check should be fine: if(setting != null) DoSomethingElse(setting); If you want to check BEFORE trying to retrieve the setting, you need to post the Type of CommonSettings.Default. It looks like a Dictionary so you might be able to get away with: if(CommonSettings

Saving a string to a .setting variable

南楼画角 提交于 2019-12-02 11:58:25
问题 I'm trying to save a string variable from my FolderBrowserDialog.SelectedPath(). Using a breakpoint I can see that the string is correctly loaded onto SelectedPath(), but I can't save that string to the .settings file for the life of me. Any help? public void LocateWoWFolder() { using (FolderBrowserDialog FileDialogWindow = new FolderBrowserDialog()) { if (FileDialogWindow.ShowDialog() == DialogResult.OK) { //Using a breakpoint here I can see that nothing is loaded to .WoWFolderLocation.

How do you write out a blank version of your config when a program is first run? [closed]

一个人想着一个人 提交于 2019-12-02 10:59:40
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . I've been making a command line tool in c# and we've ended up using a config for some parameters that will only really need setting once. Rather than provide a UI for these I was told to just set up a blank config and if the values weren't set provide a message to say where the

Save CheckedListBox Items to Settings

爷,独闯天下 提交于 2019-12-02 07:40:26
问题 I am trying to maintain a list of checked items in a CheckedListBox in User Settings and then reload them upon Application load. In my Settings.settings file, I added the following: <Setting Name="obj" Type="System.Windows.Forms.CheckedListBox.ObjectCollection" Scope="User"> <Value Profile="(Default)" /> </Setting> And, on chkList_ItemCheck , I am doing the following: Properties.Settings.Default.obj = chkList.Items; Properties.Settings.Default.Save() But for some reason, when I exit the app,

Saving a string to a .setting variable

 ̄綄美尐妖づ 提交于 2019-12-02 07:17:54
I'm trying to save a string variable from my FolderBrowserDialog.SelectedPath(). Using a breakpoint I can see that the string is correctly loaded onto SelectedPath(), but I can't save that string to the .settings file for the life of me. Any help? public void LocateWoWFolder() { using (FolderBrowserDialog FileDialogWindow = new FolderBrowserDialog()) { if (FileDialogWindow.ShowDialog() == DialogResult.OK) { //Using a breakpoint here I can see that nothing is loaded to .WoWFolderLocation. Properties.Settings.Default.WoWFolderLocation = FileDialogWindow.SelectedPath.ToString(); } } } The setting

Save CheckedListBox Items to Settings

限于喜欢 提交于 2019-12-02 05:44:32
I am trying to maintain a list of checked items in a CheckedListBox in User Settings and then reload them upon Application load. In my Settings.settings file, I added the following: <Setting Name="obj" Type="System.Windows.Forms.CheckedListBox.ObjectCollection" Scope="User"> <Value Profile="(Default)" /> </Setting> And, on chkList_ItemCheck , I am doing the following: Properties.Settings.Default.obj = chkList.Items; Properties.Settings.Default.Save() But for some reason, when I exit the app, re-open, and check the value of Properties.Settings.Default.obj , it is null . What am I doing wrong