ProTip #4: How to modify an xml file such as web.config, programmatically in c#?

Oxford Plus ProTips

Home |> ASP.Net - C# Tips |> ProTip #4: How to modify an xml file such as web.config, programmatically in c#?

Hi guys,

Welcome back to another C# ProTip, Figure 1.

Figure 1. Logo for C # ProTips!!!

One of the best ways to save important informations, such as Database Connection String, in our website, is saving in web.config file. This can be done easily, but some software projects that are written for use of many users, may need an initializing phase in first use and in this phase they will ask users some information such Username, Password, Database Connection String and so on and will set this information for next uses of system. In systems like this, we need save information in files such as xml files (specially web.config) in runtime and programmatically.

In this ProTip we see how it is possible to modify an xml file, such as web.config file, programmatically in C# language ...

A few years ago, i have wrote an article in Farsi in this field (you can read it HERE). The title of that article also is in this field but there I said that, i will write more in this subject, so now new codes:

Figure 2.

In figure 2, we listed a code inside click event of a button with name btnSet. When this button pressed, the entry of connection string in web.config file will change, figure 3.

Figure 3.

Good luck

Oxford Plus Website

Written by: Abdolreza Ghanbari
Views count: 168

This page has updated in

  • 07 June 2021

Leave a reply:

Your Name (Optional):
Your Email (Optional):
Note: Your email address will not be published.
Your Comment:

Security process: What is the sum of 10 And 1 ?
About Us

Oxford Plus ProTips
Powered by ContentO Plus v3.1