数据是
<appSettings>
<add key="WebTitle" value="标题"></add>
<add key="Key" value="关键字"></add>
<add key="Description" value="描述"></add>
<add key="Url" value="http://WWW.XXX.com"></add>
<add key="WebSite" value="www.XXX.com"></add>
<add key="FootStr" value="尾部字段"></add>
</appSettings>我选择的是
XDocument XDoc = XDocument.Load(MyConfig.WebPath + "\\Web.config");但是 之后我怎么匹配key 然后读取value呢???
<appSettings>
<add key="WebTitle" value="标题"></add>
<add key="Key" value="关键字"></add>
<add key="Description" value="描述"></add>
<add key="Url" value="http://WWW.XXX.com"></add>
<add key="WebSite" value="www.XXX.com"></add>
<add key="FootStr" value="尾部字段"></add>
</appSettings>我选择的是
XDocument XDoc = XDocument.Load(MyConfig.WebPath + "\\Web.config");但是 之后我怎么匹配key 然后读取value呢???
解决方案 »
- 一般这种并发是怎么处理的?
- 烦烦,关于MessageBox的问题...
- 请教 关于 [$value] 的用法
- Winform 如何像Web一样有层的显示和隐藏
- 基礎問題,希望得到強大的理論支持
- 解决代码重用问题,新建类来调用??
- 数据库某个列为datetime类型,可以为空,为什么绑定dateTimePicker会出错
- 如何设置treelist的checkbox只勾选一个
- 客户机与服务器的时钟如何同步?
- winfrom窗体里 string类型转化为控件对象名
- 我要升级换代,流程引擎设计器需要什么技术好?如果能做开发可以考虑外包。
- 目前流行的开发语言有.net和java,.net里包含c# vb,java里又包含啥啊?
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="y" value="this is Y"/>
</appSettings>
</configuration>读:System.Configuration.ConfigurationManager.AppSettings[“y”];
加:Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);AppSettingsSection app = config.AppSettings;app.Settings.Add("x", "this is X");config.Save(ConfigurationSaveMode.Modified);
修改:Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);AppSettingsSection app = config.AppSettings;//app.Settings.Add("x", "this is X");app.Settings["x"].Value = "this is not Y";config.Save(ConfigurationSaveMode.Modified);
删除:Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);AppSettingsSection app = config.AppSettings;app.Settings.Remove("x");config.Save(ConfigurationSaveMode.Modified);
var Query = from D in Doc.Element("").Elements("appSettings") select D;
foreach (var v in Query)
{}
LINQ告诉我对与Elemenet没有select 操作。
where D.Attribute("key").Value.ToString() == "WebTitle"
select D;
//XElement XE =(XElement) item;
//MessageBox.Show(((XElement) item).Attribute("value").Value.ToString());
纳闷不能直接转换??
DataSet ds = new DataSet();
ds.ReadXml(Application.StartupPath + "\\door.xml");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
InDoorNum =ds.Tables[0].Rows[i][0].ToString();
}希望对你有用
#region 加载 Web.Config 文件配置
if (!File.Exists(cfgFile))
throw new Exception("找不到配置文件[" + cfgFile + "]2"); DataSet ds = new DataSet();
ds.ReadXml(cfgFile);
StreamReader read = new StreamReader(cfgFile);
string firstline = read.ReadLine();
string cfg = read.ReadToEnd();
read.Close(); int start = cfg.ToLower().IndexOf("<appsettings>");
int end = cfg.ToLower().IndexOf("</appsettings>"); cfg = cfg.Substring(start, end - start + "</appsettings".Length + 1); cfgFile = "__$AppConfig.cfg";
StreamWriter write = new StreamWriter(cfgFile);
write.WriteLine(firstline);
write.Write(cfg);
write.Flush();
write.Close(); DataSet dscfg = new DataSet("cfg");
try
{
dscfg.ReadXml(cfgFile);
}
catch (Exception ex)
{
throw new Exception("加载配置文件[" + cfgFile + "]失败!\n" + ex.Message + "启动失败!");
} // BP.SystemConfig.CS_AppSettings = new System.Collections.Specialized.NameValueCollection(); BP.SystemConfig.CS_DBConnctionDic.Clear();
DataTable dt = dscfg.Tables["add"];
foreach (DataRow dr in dt.Rows)
{
string key = dr["key"] as string;
if (key == null || key == "")
continue; string value = dr["value"] as string;
if (value == null || value == "")
continue; BP.SystemConfig.CS_AppSettings.Add(key, value);
}
dscfg.Dispose(); #endregion
return true;