C#如何让多个工程使用同一个appconfig 就是我建立了一个solution 下面有多个工程 想使用同一个appconfig 直接 添加现有项 不行 因为程序会自动复制一个副本到每个工程的文件夹下 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 是工程之间的引用吗? 配置文件我想其实最好用XML保存.不过那样不安全... 不行喇 一个项目只能有一个congigu 你是保存什么信息? 推荐你使用'内裤' *.DLL 前提不是敏感数据,如果是某些敏感数据 用另外的方式.'内裤'就只能加壳子. 可以自己写个类 读取APP.Configusing System;using System.Collections.Generic;using System.Text;using System.Xml;using System.Windows.Forms;namespace DataCrypto{ public class AppSettings { public static string AppConfig() { return System.IO.Path.Combine(Application.StartupPath, "App.config");//此处配置文件在程序目录下 } public static string GetValue(string appKey) { XmlDocument xDoc = new XmlDocument(); try { xDoc.Load(AppSettings.AppConfig()); 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 ""; } } public static void SetValue(string AppKey, string AppValue) { XmlDocument xDoc = new XmlDocument(); xDoc.Load(AppSettings.AppConfig()); 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(AppSettings.AppConfig()); } }} gridview编辑按钮如何改名 自定义控件GDI+绘图闪烁问题,请高手帮忙分析下简化的代码 在C#中如何最快的加载图片到控件上 如何实现图片去除背景并叠加到另一个图片去? 那位大侠,帮忙理一下下面这几个对象的关系? 如何在C#中 启动/终止 某个服务? arrayList的问题 有什么.net打包工具吗? 有关FORM DESIGN 的例子 一般各位是如何做的??? WinForm界面上我把控件的 TabIndex 属性都排好了,为什么运行的时候按Tab 还是乱跳 在C#里,通过敲回车,可以从一个控件跳转到下一个控件,如此循环!
配置文件我想其实最好用XML保存.不过那样不安全...
推荐你使用'内裤' *.DLL
前提不是敏感数据,如果是某些敏感数据
用另外的方式.'内裤'就只能加壳子.
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Windows.Forms;namespace DataCrypto
{
public class AppSettings
{
public static string AppConfig()
{
return System.IO.Path.Combine(Application.StartupPath, "App.config");//此处配置文件在程序目录下
} public static string GetValue(string appKey)
{
XmlDocument xDoc = new XmlDocument();
try
{
xDoc.Load(AppSettings.AppConfig());
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 "";
}
} public static void SetValue(string AppKey, string AppValue)
{
XmlDocument xDoc = new XmlDocument();
xDoc.Load(AppSettings.AppConfig());
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(AppSettings.AppConfig());
}
}
}