Inline
XmlDocument xDoc = new XmlDocument(); // Gobal Declaration
string Path; // Gobal Declaration
int i; // Gobal Declaration
protected void Page_Load(object sender, EventArgs e)
{
i = Convert.ToInt32(ConfigurationManager.AppSettings["Test"].ToString());
}
protected void bt1_Click(object sender, EventArgs e)
{
Path = Server.MapPath("~/web.config");
xDoc.Load(Path);
XmlNodeList NodeList = xDoc.GetElementsByTagName("appSettings");
XmlNodeList tNodeList = NodeList[0].ChildNodes;
XmlAttributeCollection xAttColl = tNodeList[0].Attributes;
xAttColl[0].InnerXml = "Test";
xAttColl[1].InnerXml = Convert.ToString(i + 1);
xDoc.Save(Path);
Response.Write(ConfigurationManager.AppSettings["Test"].ToString());
}
Web.Config
<configuration>
<appSettings>
<add key="Test" value="0" /> <!-- Add This In Your WebConfig File -->
</appSettings>
</configuration>
No comments:
Post a Comment