C#怎么将路径保存到配置文件中,
动态获取文件路径,显示在文本框里,退出的时候把路径保存在config文件里,下次再打开程序的时候把路径从config文件中读出来显示在文件框中。

解决方案 »

  1.   

    你这里的“路径”指的是什么?不过大部分的特殊路径都用Environment类来取得。
    读取文件用streamreader和streamwriter。自己查一下就行了
      

  2.   

    StreamWriter s=new StreamWriter("your file path");
    s.Write("asdf");
      

  3.   

     /// <summary>
            /// 设置app.config中的某个key的value.
            /// </summary>
            /// <param name="AppKey">key</param>
            /// <param name="AppValue">value</param>
            public void SetValue(string AppKey, string AppValue)
            {
                XmlDocument xDoc = new XmlDocument();            //此处配置文件在程序目录下
                string strFileName = AppDomain.CurrentDomain.BaseDirectory.ToString() + "DestClerk.exe";
                xDoc.Load(strFileName + ".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(strFileName + ".config");
             }
      

  4.   

    http://topic.csdn.net/u/20090519/09/6d3543bc-7743-4b86-ac72-faa46931303d.htmlhttp://blog.csdn.net/speeter/archive/2010/06/05/5649844.aspx