解决方案 »
- 100分求救 关于 用 c# 导入导出问题
- listview增加一行时闪烁怎么解决啊?还有就是增选一行滚动条自动往下滚怎么做?
- 有人做过bolg站点吗?知道的来看一下
- 我只想实现用鼠标来移动datagrid的列的宽度(仅此而已)。如何做呢,能否给我具体点的代码吗?(不是在winform)。
- C#中Socket编程实现类似QQ聊天的功能,IP地址无法确认!
- 不知道能不能实现一个WEB版的服务端,求大神指点
- 重构代码 真是一个 既枯燥又耗时间的工作
- web如何访问网域内的机器的文件路径
- 水晶报表已注册,安装几台机子只有最重要一台出错,无法找到密钥号码或密钥无效,急煞我也
- 请问播放声音图像等多媒体文件要用哪些类
- C#对 彩色压缩的TIFF图片格式的转换
- 外网 连接数据库 sql2005
{
XmlDocument xDoc = new XmlDocument();
try
{
xDoc.Load(path);
//xDoc.Load(System.Windows.Forms.Application.ExecutablePath+".config");
XmlNode xNode;
XmlElement xElem;
xNode = xDoc.SelectSingleNode("//appSettings");
xElem = (XmlElement)xNode.SelectSingleNode("//add[@key='"+appKey+"']");
if(xElem!=null)
return xElem.GetAttribute("value");
else
return "";
}
catch(Exception)
{
return "";
}
}
/// <summary>
/// 修改配置文件
/// </summary>
/// <param name="connString"></param>
public static void UpdateConfig(string p_strKey, string p_strValue)
{
try
{
string m_strFullPath = "";
Assembly Asm = Assembly.GetExecutingAssembly();
XmlDocument xmlDoc = new XmlDocument(); m_strFullPath = Asm.Location.Substring(0, (Asm.Location.LastIndexOf("\\") + 1)) + "YourApplication.exe.config";
xmlDoc.Load(m_strFullPath); XmlNodeList nodeList = xmlDoc.SelectSingleNode("/configuration/appSettings").ChildNodes;
foreach (XmlNode xn in nodeList)//遍历所有子节点
{
XmlElement xe = (XmlElement)xn; if (xe.GetAttribute("key").IndexOf(p_strKey) != -1)
{
xe.SetAttribute("value", p_strValue);
}
}
xmlDoc.Save(m_strFullPath);
}
catch (System.NullReferenceException NullEx)
{
throw NullEx;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 修改链接字符串
/// </summary>
/// <returns></returns>
private bool UpdateConfig(string path, bool PartnerSystem)
{
System.IO.FileInfo FileInfo = new System.IO.FileInfo(dir + path);
if (!FileInfo.Exists)
{
throw new InstallException("Missing config file :" + this.Context.Parameters["targetdir"] + "web.config");
}
System.Xml.XmlDocument xmlDocument = new System.Xml.XmlDocument();
xmlDocument.Load(FileInfo.FullName);
bool FoundIt = false;
foreach (System.Xml.XmlNode Node in xmlDocument["configuration"]["connectionStrings"])
{
if (Node.Name == "add")
{
if (Node.Attributes.GetNamedItem("name").Value == "Connection")
{
Node.Attributes.GetNamedItem("connectionString").Value = String.Format("server={0};database={1};uid={2};pwd={3};pooling=true;charset=gbk;", ServerName, DBName, AdminName, AdminPwd);
FoundIt = true;
}
}
}
if (PartnerSystem)
{
foreach (System.Xml.XmlNode Node in xmlDocument["configuration"]["appSettings"])
{
if (Node.Name == "add")
{
if (Node.Attributes.GetNamedItem("key").Value == "PartnerSystem")
{
Node.Attributes.GetNamedItem("value").Value = this.Context.Parameters["partner"].ToString();
FoundIt = true;
}
}
}
}
if (!FoundIt)
{
throw new InstallException("Error when writing the config file: web.config");
}
xmlDocument.Save(FileInfo.FullName);
return FoundIt;
}希望对你有帮助
config.AppSettings.Settings["abc"].Value = abc;
我对操作XML文件不怎么会,
我想把config里的每个节点都显示到窗体上相应的文本框里,实现这样的一个功能方法如何实现,还请帮帮忙!
config.AppSettings.Settings["abc"].Value = abc;
或者是用xml
解决了原来是 config里的注释,把注释去掉了都没有问题了