첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
유용한 소스 코드가 있으면 icodebroker@naver.com으로 보내주시면 감사합니다.
블로그 자료는 자유롭게 사용하세요.

■ Application 클래스 : 격리된 저장소에 응용 프로그램 속성 저장하기/로드하기

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

using System.IO;

using System.IO.IsolatedStorage;

using System.Windows;

 

namespace DS.Test.WPF

{

    /// <summary>

    /// 메인 애플리케이션

    /// </summary>

    public partial class MainApplication : Application

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Field

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

 

        #region Field

 

        /// <summary>

        /// 파일 경로

        /// </summary>

        private string filePath = "Application.txt";

 

        #endregion

 

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

        ////////////////////////////////////////////////////////////////////////////////////////// Protected

 

        #region 시작시 처리하기 - OnStartup(e)

 

        /// <summary>

        /// 시작시 처리하기

        /// </summary>

        /// <param name="e">이벤트 인자</param>

        protected override void OnStartup(StartupEventArgs e)

        {

            IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetUserStoreForDomain();

 

            try

            {

                using(IsolatedStorageFileStream isolatedStorageFileStream =

                    new IsolatedStorageFileStream(this.filePath, FileMode.Open, isolatedStorageFile))

                {

                    using(StreamReader streamReader = new StreamReader(isolatedStorageFileStream))

                    {

                        while(!streamReader.EndOfStream)

                        {

                            string[] keyValueArray = streamReader.ReadLine().Split(new char[] {','});

                            

                            Properties[keyValueArray[0]] = keyValueArray[1];

                        }

                    }

                }

            }

            catch(FileNotFoundException fileNotFoundException)

            {

                MessageBox.Show(fileNotFoundException.Message);

            }

        }

 

        #endregion

 

        #region 종료시 처리하기 - OnExit(e)

 

        /// <summary>

        /// 종료시 처리하기

        /// </summary>

        /// <param name="e">이벤트 인자</param>

        protected override void OnExit(ExitEventArgs e)

        {

            IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetUserStoreForDomain();

 

            using(IsolatedStorageFileStream isolatedStorageFileStream =

                new IsolatedStorageFileStream(this.filePath, FileMode.Create, isolatedStorageFile))

            {

                using(StreamWriter streamWriter = new StreamWriter(isolatedStorageFileStream))

                {

                    foreach(string key in this.Properties.Keys)

                    {

                        streamWriter.WriteLine("{0},{1}", key, Properties[key]);

                    }

                }

            }

        }

 

        #endregion

    }

}

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

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요