.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

Readxml -- Problem

Posted By: Narayanan     Posted Date: May 25, 2011    Points:5   Category :C#
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;
//Try to find the textbox
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

Responses
Author: Dhiraj Ranka             
Posted Date: May 25, 2011     Points: 20   

Hi,

What is the issue?

Hope this helps.

Thanks & Regards,
Dhiraj Ranka
http://www.twitter.com/dhirajranka | http://www.dhirajranka.com
Author: Narayanan             
Posted Date: May 25, 2011     Points: 20   

Hi Dhiraj Ranka,
Thanks for u reply.I didn't get <port0> to <port2> value.But i get port3 value.How to solve this problem
Please help me.
This is my code....
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;
//Try to find the textbox
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;

please help me
Regards,
Lakshmi Narayanan.S

Regards, Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend