You already converted the virtual path to a physical path, so the second time you try the conversion fails as it already is a physical path:
protected void btnSubmit_Click(object sender, EventArgs e)
{
XmlDocument xmlDoc = new XmlDocument();
string xmlPath = Path.Combine(Server.MapPath("~/App_Data"), "Sample.xml");
if (!File.Exists(xmlPath))
{
throw new Exception("Cannot find xml file");
}
else
{
xmlDoc.Load(xmlPath);
XmlElement parentElement = xmlDoc.CreateElement("Comments");
XmlElement name = xmlDoc.CreateElement("Name");
name.InnerText = txtName.Text;
parentElement.AppendChild(name);
parentElement.AppendChild(Location);
xmlDoc.DocumentElement.AppendChild(parentElement);
xmlDoc.Save(xmlPath);
BindDataList();
}
Regards,
— Manfred