Program to read value from AppSettings section in C# using XDocument class

Rajnilari2015
Posted by Rajnilari2015 under C# category on | Points: 40 | Views : 383
The below program will do the work


using System;
using System.Xml.Linq;

namespace MakeEnvVars
{
class Program
{
static void Main(string[] args)
{
string fileName = @"D:\Web.config";
XDocument doc = XDocument.Load(fileName);
string message = string.Empty;
var elements = doc.Descendants("appSettings").Descendants("add");
foreach (XElement element in elements)
{
message = $"SET {element.FirstAttribute.Value}=\"{element.LastAttribute.Value}\"";
Console.WriteLine(message);
}

Console.ReadKey();
}
}
}

Comments or Responses

Login to post response