.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 >> Code Snippets >> File Operation >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Create XML file in ASP.NET

Posted By:Athira Sreejith       Posted Date: March 24, 2009    Points: 10    Category: File Operation    URL: http://www.dotnetspark.com  
 

Below example shows how to create XML file pragmatically using C# in asp.net

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Xml;

public partial class XMLsample : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

}

protected void btnSubmit_Click(object sender, EventArgs e)

{

string fname = Server.MapPath("Products.xml");

XmlTextWriter tw = new XmlTextWriter(fname, null);

tw.Formatting = Formatting.None;

tw.WriteStartDocument();

tw.WriteStartElement("ProductID");

tw.WriteStartElement("ProductName");

tw.WriteStartAttribute("Product", "Stationary");

tw.WriteStartAttribute("Name", "Cinthol");

tw.WriteStartAttribute("Quantity", "9");

tw.WriteStartAttribute("Price", "45");

tw.WriteEndElement();

tw.WriteEndElement();

tw.WriteEndDocument();

tw.Flush();

tw.Close();

}

}


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

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