Error in list saved in user settings: strings doesn't save RRS feed

  • Question

  •  I have an List saved in my user settings, it should save several strings, but when I check its value (by Settings.Default.FileList.Count) it displays that the value is 0, when I save a string, it displays the number of strings saved, but when I Change of form or I restart the app, it's again 0.

    I've already tried using Save(); method, and even, the Upgrade(); method but it stills.

    Friday, July 6, 2018 7:57 PM

All replies

  • Hi,

    >>I have an List saved in my user settings, it should save several strings...

    How did you store a List to the settings? What the type of your property is?

    Please provide the code you added to the list or other methods you used.

    In fact, you just need to save the settings with:




    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Saturday, July 7, 2018 5:31 AM
  • ood Day, I Need to Deserialize Different XML Files In My Windows Forms Application, It Should Work Like The Following.1234So I have Tried So Much Alternatives, But This Is The Code That Is The Closest To My Goal.

    `private OpenFileDialog openFileDialog1 = new OpenFileDialog();
        private void ImportIcon_Click(object sender, EventArgs e)
            openFileDialog1.Filter = "Analytica Files (*.analy) |*.analy";
            openFileDialog1.Multiselect = true;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
                var Path = openFileDialog1.FileName;
                foreach (string file in openFileDialog1.FileNames)
                //XmlSerializer XS = new 
                //StreamReader Reader = new StreamReader(Path);
                //Information i;
                //var input = XS.Deserialize(Reader);
                MessageBox.Show("Exception Found In File");
        foreach (string TheFile in Settings.Default.FileList)
                Reminders.TaskUC Task = new Reminders.TaskUC();
                Point TP = new Point();
                Task.Name = "Task" + Settings.Default.Counter.ToString();
                TP.Y = 1;
                int Add = 300;
                int Result = Start;
                int Distance = 100;
                Control Last = Controls[Controls.Count - 1];
                TP.X = Last.Location.X + Distance;
                if (Settings.Default.FileList.Count == 1)
                    TP.X = 300;
                Size PanelWidth = new Size();
                PanelWidth.Width = ReminderPanel.Width + 300;
                PanelWidth.Height = ReminderPanel.Height;
                Task.Location = TP;
                ReminderPanel.Size = PanelWidth;
                XmlSerializer XS = new XmlSerializer(typeof(List<Information>));
                FileStream Read = new FileStream(TheFile, FileMode.Open, 
                FileAccess.Read, FileShare.Read);
                Information i = new Information();
                Task.TitleBox.Text = i.Title1;
                This is the class code:
                 public class Information
           private string Title;
           private string Description;
           private DateTime Date;
           private DateTime Hour;
           private bool Check;
           public string Title1
            get { return Title; }
            set { Title = value; }
        public string Description2
            get { return Description; }
            set { Description = value; }
        public DateTime Date3
            get { return Date; }
            set { Date = value; }
        public DateTime Hour4
            get { return Hour; }
            set { Hour = value; }
        public bool Check5
            get { return Check; }
            set { Check = value;}
    public class SaveXML
        public static void SaveData(object obj, string filename)
            XmlSerializer SR = new XmlSerializer(obj.GetType());
            TextWriter Writer = new StreamWriter(filename);
            SR.Serialize(Writer, obj);
        } `
    As you can see, FileList is a List<string> saved in my user settings, to get and save the openfiledialog file paths in it, then to deserialize it, but it has a problem that doesn't really save the strings even when the Save(); method is called.

    • Moved by CoolDadTx Monday, July 9, 2018 2:42 PM Winforms related
    • Merged by Stanly Fan Tuesday, July 10, 2018 2:51 AM the same thread
    Monday, July 9, 2018 4:14 AM
  • Please post a concise and complete example. Cause your code fragments seems to be incomplete and it looks like you should look into SRP.

    Thus separate UI from logic and data.

    Monday, July 9, 2018 9:10 AM