.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

Dynamic creation of xml Elements in C#.net

Posted By: Narayanan     Posted Date: May 24, 2011    Points:5   Category :C#
Hi friends,
I created a Dynamic textbox and insert a value into XML.I send my code for u reference.
My code for XML Creation.
string sFilename = xmlpath;
XmlDocument xmlDoc = new XmlDocument();
String XmlSpecification = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
XmlSpecification = XmlSpecification + Environment.NewLine + "<Testing></Testing>";
File.AppendAllText(xmlpath, XmlSpecification);
xmlDoc.Load(sFilename);
XmlElement elmXML = xmlDoc.CreateElement("Configuration");
string strConfiguration = String.Empty;
for (int index = 0; index < 3; 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();
strConfiguration = strConfiguration + Environment.NewLine + @"<str>" + Userprefrenece.txt1 + "</str>";

}

elmXML.InnerXml = strConfiguration;
xmlDoc.DocumentElement.AppendChild(elmXML);
xmlDoc.Save(sFilename);
MessageBox.Show("Saved Successfully");
I saved successfully. How can retrieve from XML. But I didn't get correct.
My XML Data

<?xml version="1.0" encoding="utf-8" ?>
- <Testing>
- <Configuration>
<str>NARAAYANAN</str>
<str>DELL</str>
<str>SUCCESS</str>
</Configuration>
</Testing>
retrieve is my problem.How can i retrieve data from xml.and store in the textbox .Please help me Urgent
Regards,
Lakshmi Narayanan.S

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

Hi,

You can follow this link to read your XML file

http://support.microsoft.com/kb/307548

Hope this helps

Hope this helps.

Thanks & Regards,
Dhiraj Ranka
http://www.twitter.com/dhirajranka | http://www.dhirajranka.com


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