• <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

            『站在風(fēng)口浪尖緊握住鼠標(biāo)旋轉(zhuǎn)!』 http://www.cnblogs.com/twzheng

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

            通過Properties.Settings用代碼形式讀寫app.config文件,其中Properties.Settings變量的范圍"scope"都設(shè)置為用戶"user"(注:如果改為"Application",編譯時(shí)系統(tǒng)提示其為只讀屬性),讀寫都正常,并且重新打開exe文件時(shí),上次輸入的值仍然存在,但是手動(dòng)打開"test.exe.config",所有的設(shè)置變量值均為空,寫入的值都保存到什么地方去了呢?臨時(shí)文件?我用360安全衛(wèi)士清除臨時(shí)文件后在此打開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 譚文政 閱讀(3483) 評(píng)論(4)  編輯 收藏 引用 所屬分類: windows 編程

            評(píng)論

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

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

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

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

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

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

            這里我寫成了兩個(gè)方法,以供大家參考!
            一,命名空間
            using System;
            using System.Configuration;
            using System.Xml;
            二,方法
            //讀取Value值
            public static string GetConfigString(string key)
            {
            //
            // TODO: 在此處添加構(gòu)造函數(shù)邏輯
            //
            return ConfigurationSettings.AppSettings[key];
            }
            //寫操作
            public static void SetValue(string AppKey,string AppValue)
            {
            XmlDocument xDoc = new XmlDocument();
            //獲取可執(zhí)行文件的路徑和名稱
            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");
            }
              回復(fù)  更多評(píng)論
              

            国产激情久久久久影院老熟女免费| 久久精品视频一| 国产精品美女久久久m| 国产三级久久久精品麻豆三级| 99久久久国产精品免费无卡顿| 91精品观看91久久久久久| 久久精品一区二区影院| 久久亚洲精品无码VA大香大香| 国产产无码乱码精品久久鸭 | 国产精品久久久久…| 久久美女人爽女人爽| 一本久道久久综合狠狠躁AV| 久久人爽人人爽人人片AV| 精品无码久久久久久国产| 中文字幕乱码久久午夜| 久久激情亚洲精品无码?V| 久久香蕉国产线看观看精品yw| 午夜精品久久久久久影视riav| 青草影院天堂男人久久| 亚洲人成网站999久久久综合| 久久久久AV综合网成人| 亚洲欧洲久久久精品| 久久天天躁狠狠躁夜夜2020| 无码AV波多野结衣久久| 亚洲欧美日韩久久精品| 亚洲精品国产成人99久久| 久久偷看各类wc女厕嘘嘘| 国产亚洲精品久久久久秋霞| 久久久久亚洲精品无码网址| 久久综合九色综合久99| 国产精品久久久亚洲| 亚洲精品乱码久久久久久久久久久久 | 久久久久国产一区二区| 久久精品视频免费| 国产91色综合久久免费分享| 日本强好片久久久久久AAA | 亚州日韩精品专区久久久| 国产精品久久久99| 久久精品视屏| 中文字幕久久精品| 亚洲中文字幕无码久久综合网|