■ 애플리케이션 구성 파일 변경하기

----------------------------------------------------------------------------------------------------


TestProject.zip


app.config

 

 

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

    <startup>

        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />

    </startup>

    <appSettings>

        <add key="Language" value="Ruby" />

    </appSettings>

</configuration>

 

 

Program.cs

 

 

using System.Configuration;

using System.IO;

using System.Reflection;

 

namespace TestProject

{

    /// <summary>

    /// 프로그램

    /// </summary>

    class Program

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Static

        //////////////////////////////////////////////////////////////////////////////// Private

 

        #region 프로그램 실행하기 - Main()

 

        /// <summary>

        /// 프로그램 실행하기

        /// </summary>

        private static void Main()

        {

            string applicationFilePath      = Assembly.GetExecutingAssembly().Location;

            string applicationDirectoryPath = Path.GetDirectoryName(applicationFilePath);

            string applicationFileName      = Path.GetFileName(applicationFilePath);

            string configurationFilePath    = Path.Combine(applicationDirectoryPath, applicationFileName + ".config");

 

            ExeConfigurationFileMap exeConfigurationFileMap = new ExeConfigurationFileMap();

 

            exeConfigurationFileMap.ExeConfigFilename = configurationFilePath;          

 

            Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(exeConfigurationFileMap,

                                              ConfigurationUserLevel.None);

 

            configuration.AppSettings.Settings["Language"].Value = "C#";

 

            configuration.AppSettings.Settings.Add("Version", "7.0");

 

            configuration.Save();

        }

 

        #endregion

    }

}

 

----------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요