Linq修改Web.config的连接字符串
2016-07-17 20:13
441 查看
1、Linq修改Web.config的连接字符串
2、Linq修改Web.config的连接字符串
3、其他方法
XmlDocument objXML = new XmlDocument();
string xmlPath = Environment.CurrentDirectory + "\\ModifyConfig.exe.config";
objXML.Load(xmlPath);
XmlNode rootNode = objXML.DocumentElement;
foreach (XmlNode objNode in rootNode.ChildNodes)
{
if (objNode.Name == "connectionStrings")
{
objNode.FirstChild.Attributes["connectionString"].Value = this.txtValue.Text.Trim();
objXML.Save(xmlPath);
}
}
string xmlPath = Environment.CurrentDirectory + "\\ModifyConfig.exe.config"; XElement xml = XElement.Load(xmlPath); var temp = from k in xml.Descendants("connectionStrings").Elements("add") where k.Attribute("name").Value == "connStr" select k; var query = temp.SingleOrDefault(); if (query != null) { query.Attribute("connectionString").Value = this.txtValue.Text; xml.Save(xmlPath); }
2、Linq修改Web.config的连接字符串
var tempapp = from k in xml.Descendants("appSettings").Elements("add") where k.Attribute("key").Value == "pas" select k; var queryapp = temp.SingleOrDefault(); if (query != null) { query.Attribute("value").Value = newpassword; xml.Save(path); }
3、其他方法
XmlDocument objXML = new XmlDocument();
string xmlPath = Environment.CurrentDirectory + "\\ModifyConfig.exe.config";
objXML.Load(xmlPath);
XmlNode rootNode = objXML.DocumentElement;
foreach (XmlNode objNode in rootNode.ChildNodes)
{
if (objNode.Name == "connectionStrings")
{
objNode.FirstChild.Attributes["connectionString"].Value = this.txtValue.Text.Trim();
objXML.Save(xmlPath);
}
}
相关文章推荐
- 二、android.support.v7.app.ActionBarActivity is deprecated; use AppCompatActivity instead
- Scala vs. Groovy vs. Clojure
- App下载更新、数据库断点续传、通知栏更新下载进度、Https传服务器Json并且解析对象
- 用Delphi实现文件下载的几种方法
- 广播的最佳实践-实现强制下线功能
- 自我介绍及决心书
- 弱智dp----路径问题
- 二叉树的镜像
- D. Swaps in Permutation
- Linux watch命令
- Evaluate Reverse Polish Notation
- tomcat 性能优化
- 最大子序列和问题四种解(O)
- 九宫格的计算
- iOS多线程编程——浅谈GCD
- curl进行传值(post提交请求)
- C++应用程序性能优化——程序的启动过程
- 拓扑排序以及关键路径总结
- Oscache缓存总结
- 支持向量机导论