Hello,
I am learning how to using XML documents to store data.
I get this error:
Access to the path "c:\inetpub\wwwroot\Info.xml" is denied.
I have tried with the full path of the file, with / infront of the file.
How do I get the data in too the xml document
Here is the code below:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;
namespace xDoc
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox txtName;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.TextBox txtEmail;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.TextBox txtComments;
protected System.Web.UI.WebControls.Button btnSubmit;
protected System.Web.UI.WebControls.Button btnClear;
protected System.Web.UI.WebControls.Label Label4;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnSubmit_Click(object sender, System.EventArgs e)
{
try
{
XmlTextWriter xDoc = new XmlTextWriter(Request.MapPath("Info.xml"),
System.Text.Encoding.Default);
xDoc.Formatting = Formatting.Indented;
xDoc.WriteStartDocument();
xDoc.WriteComment("2004 eXQue");
xDoc.WriteStartElement("Comments");
xDoc.WriteStartElement("Name");
xDoc.WriteString(txtName.Text);
xDoc.WriteEndElement();
xDoc.WriteStartElement("Email");
xDoc.WriteString(txtEmail.Text);
xDoc.WriteEndElement();
xDoc.WriteStartElement("Comments");
xDoc.WriteString(txtComments.Text);
xDoc.WriteEndElement();
xDoc.WriteEndDocument();
xDoc.Close();
Label4.Text = "Done";
}
catch (Exception ex)
{
Label4.Text = ex.Message.ToString();
}
}
}
}
TIA
Aaron