vendredi 27 novembre 2015

C# How to Serialize XML from text/checbox on a loop based on button click

I am trying to serialize values in a user control based on a button click: C# WinForm Validate Checkbox and Error if at least one is unselected

The serialzation is not unlike this

I have 1 problem and few questions.

The problem is, I cannot call this from within my foreach process on button click (it is outwith of this).

The questions:

I am defining a string for each checkbox upon check; the name in the string should be related to the public string used for the XML section, is this a sensible approach? e.g.

public static string CheckBoxString;
        private void CheckBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (CheckBox1.Checked)
            {
                CheckBoxString = "SESSIONNAMEValue";
            }
        }

Next question:

If I have multiple user controls all writing to the same XML at various stages e.g. user control 1 writes the sessionname for each checkbox, two writes name for each checkbox, three writes time for each checkbox.

How should I best manage this? I didn't think update the file was the best approach but I didnt want to write everything back to the form to store and process at the end...

Example XML:

<CONFIG1>
   <SESSIONNAME>SOMETHINGHERE</SESSIONNAME>
   <NAME>NAMEHERE</NAME>
   <DATETIME>DATE</DATETIME>
</CONFIG1>

<CONFIG2>
   <SESSIONNAME>SOMETHINGHERE</SESSIONNAME>
   <NAME>NAMEHERE</NAME>
   <DATETIME>DATE</DATETIME>
</CONFIG2>




Aucun commentaire:

Enregistrer un commentaire