I explain my Project
Step:1
I created a Dynamic textbox.(eg:4)
Step:2
I saved data into xmlfile based on textbox.
Step:3
I retrieve from xmlfile based on textbox(on that save format).
I finished first 2 steps. my problem is 3 step.
Please Help me.
I send my code for u reference:
Declaration part
public static System.Windows.Forms.GroupBox gb;
public static string ModifiedPath = Path.GetDirectoryName(Application.ExecutablePath) + "\\Folder\\dataText";
Step:1
To create a groupbox and textbox:
gb = new GroupBox();
gb.Name = "GroupName";
gb.Text = "Virtual COM Port";
gb.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
gb.Width = 300;
gb.Height = 150;
gb.Left = 10;
gb.Top = 15;
this.Controls.Add(gb);
int i;
for (i = 0; i < 4; i++)
{
TextBox txt = new TextBox();
txt.Name = "Textbox" + i.ToString();
txt.Text = "Testtext" + i.ToString();
txt.Width = 150;
txt.Height = 20;
txt.Left = 100;
txt.Top = 20 + (txt.Height * i) + (10 * i);
gb.Controls.Add(txt);
}
Step:2
To create a xmlfile and saved data from textbox.
string sFilename = xmlpath;
XmlDocument xmldoc = new XmlDocument();
XmlDeclaration xmldec = xmldoc.CreateXmlDeclaration("1.0", null, null);
xmldoc.AppendChild(xmldec);
XmlElement xmlele = xmldoc.CreateElement("Root");
xmldoc.AppendChild(xmlele);
for (int index = 0; index < 4; index++)
{
string targetTextBox = "Textbox" + index;
int textBoxIndex = gb.Controls.IndexOfKey(targetTextBox);
if (textBoxIndex != -1)
{
TextBox foundTextBox = (TextBox)gb.Controls[textBoxIndex];
Userprefrenece.txt1 = foundTextBox.Text;
}
String str = "port" + index.ToString();
XmlElement port = xmldoc.CreateElement(str);
xmlele.AppendChild(port);
port.InnerText = Userprefrenece.txt1;
}
xmldoc.Save(sFilename);
MessageBox.Show("Saved Successfully");
In my XML file data:
<?xml version="1.0"?>
<Root>
<port0>NARAYANAN</port0>
<port1>DELL</port1>
<port2>C#.NET</port2>
<port3>SUCCESS</port3>
</Root>
Step:3
??????(What will i do)
My output like this,
textbox1 =Port0 data
textbox2 =Port1 data
textbox3 =Port3 data
textbox4 =Port4 data
Regards,
Lakshmi Narayanan.S
[edit]Code blocks added, some formatting - OriginalGriff[/edit]