C#怎么将路径保存到配置文件中, C#怎么将路径保存到配置文件中,动态获取文件路径,显示在文本框里,退出的时候把路径保存在config文件里,下次再打开程序的时候把路径从config文件中读出来显示在文件框中。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你这里的“路径”指的是什么?不过大部分的特殊路径都用Environment类来取得。读取文件用streamreader和streamwriter。自己查一下就行了 StreamWriter s=new StreamWriter("your file path");s.Write("asdf"); /// <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"); } http://topic.csdn.net/u/20090519/09/6d3543bc-7743-4b86-ac72-faa46931303d.htmlhttp://blog.csdn.net/speeter/archive/2010/06/05/5649844.aspx c#问题 关于GZipStream压缩输出流的问题? 求助 救救我啊,怎么在IE客户端没有权限写服务器端XML文件呢???? c#大型程序如何开发? 更新服务器端控件的Eanble设置 我在编译程序的时候出现一下如下问题,不知那位见过帮忙看看,谢谢 求助,怎么解决下面两个难点! 在win2003 下,怎么处理创建Asp.net应用程序,报的错误? 關於數據類型的一個簡單問題 取消屏保 有比2项组合法更快速的解决方法吗,请教
读取文件用streamreader和streamwriter。自己查一下就行了
s.Write("asdf");
/// 设置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");
}