• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            twzheng's cppblog

            『站在風口浪尖緊握住鼠標旋轉!』 http://www.cnblogs.com/twzheng

              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
              136 隨筆 :: 78 文章 :: 353 評論 :: 0 Trackbacks
            [問]VS2005,C#winform程序,代碼修改app.config的結果保存到哪里了?

            通過Properties.Settings用代碼形式讀寫app.config文件,其中Properties.Settings變量的范圍"scope"都設置為用戶"user"(注:如果改為"Application",編譯時系統提示其為只讀屬性),讀寫都正常,并且重新打開exe文件時,上次輸入的值仍然存在,但是手動打開"test.exe.config",所有的設置變量值均為空,寫入的值都保存到什么地方去了呢?臨時文件?我用360安全衛士清除臨時文件后在此打開exe文件,上次輸入的值依然存在。有誰知道這是怎么回事?

            示例代碼:
            private void button1_Click(object sender, EventArgs e)

               //讀操作,將讀到的值送textBox1顯示 
               Properties.Settings config = Properties.Settings.Default; 
               textBox1.Text = config.myvar;
            }

            private void button2_Click(object sender, EventArgs e)

               //寫操作,將textBox2里的值寫入myvar 
               Properties.Settings config = Properties.Settings.Default; 
               config.myvar = textBox2.Text; 
               config.Save();
            }
            posted on 2008-03-17 21:32 譚文政 閱讀(3482) 評論(4)  編輯 收藏 引用 所屬分類: windows 編程

            評論

            # re: [問]VS2005,C#winform程序,代碼修改app.config的結果保存到哪里了?[未登錄] 2008-03-18 08:24 cppexplore
            @苦味酸
            c#的問題建議去博客園問,這邊看樣子知道的不多。另有留言給你。  回復  更多評論
              

            # re: [問]VS2005,C#winform程序,代碼修改app.config的結果保存到哪里了? 2008-03-18 09:06 苦味酸
            @cppexplore
            謝謝  回復  更多評論
              

            # re: [問]VS2005,C#winform程序,代碼修改app.config的結果保存到哪里了? 2008-03-18 10:55 苦味酸
            自己找到問題答案了。。。

            當Properties.Settings變量的范圍"scope"設置為用戶"user"時,通過上述方式讀寫操作并不是操作了"test.exe.config"文件,實際操作的文件保存在"C:\Documents and Settings\Administrator\Local Settings\Application Data\"路徑下面(注:Administrator是當前用戶文件夾),文件名字叫"user.config"。點擊工程Properties頁面中"設置"選項卡的"同步"按鈕會提示這個路徑。  回復  更多評論
              

            # re: [問]VS2005,C#winform程序,代碼修改app.config的結果保存到哪里了? 2008-03-18 11:05 苦味酸
            用下面的方法可以操作應用程序文件夾下的配置文件:

            在winform中使用程序讀取和修改App.config里面的appSettings當中的Value值

            這里我寫成了兩個方法,以供大家參考!
            一,命名空間
            using System;
            using System.Configuration;
            using System.Xml;
            二,方法
            //讀取Value值
            public static string GetConfigString(string key)
            {
            //
            // TODO: 在此處添加構造函數邏輯
            //
            return ConfigurationSettings.AppSettings[key];
            }
            //寫操作
            public static void SetValue(string AppKey,string AppValue)
            {
            XmlDocument xDoc = new XmlDocument();
            //獲取可執行文件的路徑和名稱
            xDoc.Load(System.Windows.Forms.Application.ExecutablePath + ".config");

            XmlNode xNode;
            XmlElement xElem1;
            XmlElement xElem2;
            xNode = xDoc.SelectSingleNode("//appSettings");

            xElem1 = (XmlElement)xNode.SelectSingleNode("//add[@key='" + AppKey + "']");
            if ( xElem1 != null ) xElem1.SetAttribute("value",AppValue);
            else
            {
            xElem2 = xDoc.CreateElement("add");
            xElem2.SetAttribute("key",AppKey);
            xElem2.SetAttribute("value",AppValue);
            xNode.AppendChild(xElem2);
            }
            xDoc.Save(System.Windows.Forms.Application.ExecutablePath + ".config");
            }
              回復  更多評論
              

            亚洲国产成人久久综合区| 99久久精品国产高清一区二区| 亚洲国产二区三区久久| 东京热TOKYO综合久久精品| 99久久精品九九亚洲精品| 亚洲国产精品嫩草影院久久| 国内精品久久久久影院优| 久久久久亚洲AV成人网| 欧美黑人又粗又大久久久| 国产三级精品久久| 性欧美丰满熟妇XXXX性久久久| 久久精品国产福利国产秒| 久久亚洲sm情趣捆绑调教| 91久久香蕉国产熟女线看| 精品国产乱码久久久久软件| 国产亚洲精午夜久久久久久| 久久久亚洲欧洲日产国码是AV| 国产福利电影一区二区三区久久久久成人精品综合 | 国产叼嘿久久精品久久| 精品久久久久久中文字幕大豆网| 国产一级持黄大片99久久| 欧美日韩精品久久免费| 久久精品国产只有精品66| 狠色狠色狠狠色综合久久| 99久久综合国产精品免费| 久久国产成人| 成人亚洲欧美久久久久| 国产精品久久自在自线观看| 午夜精品久久久久久99热| 久久精品成人欧美大片| 三级片免费观看久久| 久久久久国产视频电影| 狠狠色综合久久久久尤物| 香蕉久久一区二区不卡无毒影院| 亚洲精品无码久久千人斩| 中文字幕乱码人妻无码久久| 亚洲日本va午夜中文字幕久久 | 久久综合久久自在自线精品自| 国产精品久久久久久久app | 亚洲精品无码久久久| 午夜精品久久久久久|