Please refer this code.
HTML
Location
<asp:TextBox ID="txtLocation" runat="server" />
<br />
<br />
Delete Location path
<asp:Button ID="btnDeleteLocationPath" runat="server" Text="Delete Location Path"
OnClick="DeleteLocationPath" />
Namespace
using System.Xml;
C#
protected void DeleteLocationPath(object sender, EventArgs e)
{
string path = Server.MapPath("~/Web.Config");
XmlDocument xDoc = new XmlDocument();
xDoc.Load(path);
XmlNodeList list = xDoc.DocumentElement.SelectNodes("location");
if (list.Count > 0)
{
foreach (XmlNode node in list)
{
if (node.Attributes["path"].Value == this.txtLocation.Text.Trim())
{
node.ParentNode.RemoveChild(node);
XmlTextWriter xwriter = new XmlTextWriter(path, null);
xDoc.WriteTo(xwriter);
xwriter.Close();
break;
}
}
}
}