You have recently completed creating an application that uses an application configuration file.
This configuration file contains a section named EmployeeSection, which contains Employee elements.
You are required to view the contents of the EmployeeSection element.
You need to ensure that the EmployeeSection element outputs its contents to the console.
What should you do?
A.
Use the following code:
Configuration config = ConfigurationManager.OpenExeConfiguration( ConfigurationUserLevel.None);
ConfigurationSection section = config.GetSection(“EmployeeSection”);
Console.WriteLine(section.Contents);
B.
Use the following code:
ConfigurationSection section = Config.GetSection(“EmployeeSection”);
Console.WriteLine(section.SectionInformation.GetRawXml ());
C.
Use the following code:
string section = ConfigurationSettings.AppSettings [“EmployeeSection”];
Console.WriteLine(section);
D.
Use the following code:
Configuration config = ConfigurationManager.OpenExeConfiguration( ConfigurationUserLevel.None);
ConfigurationSection section = config.GetSection (“EmployeeSection”);
Console.WriteLine(section.SectionInformation.GetRawXml ());
Explanation:
This code opens the application configuration file, retrieves the EmployeeSection element and outputs the contents as raw XML. The OpenExeConfiguration method takes a ConfigurationUserLevel enumeration value to indicate the visibility of the configuration settings. The value None means that the settings apply to all users. The OpenExeConfiguration method returns a Configuration object representing the current configuration settings. The GetSection method of the Configuration object can then be used to retrieve a specified section of the configuration file. The GetSection method accepts a section name and returns a ConfigurationSection object representing the specified section, if it is found. In this scenario, you pass the GetSection method the name of the EmployeeSection, and it returns a ConfigurationSection representing the EmployeeSection. You can then use this ConfigurationSection object to access information about the section of the configuration file. The SectionInformation property of the ConfigurationSection object retrieves
section-specific settings, including contents. The GetRawWml method returns the XML content of the EmployeeSection. The WriteLine method then outputs the contents of the console.
Incorrect Answers:
A: You should not use the code that accesses the Contents property of the ConfigurationSection class because the ConfigurationSection class contains no such