在web里和win程序里如何调用自己的配置文件?请达人解惑
解决方案 »
- Entity Framework 按条件多个Where性能问题
- 没天理,下面的测试代码都不通过?
- excel插入后数据类型问题。
- 运用记录集,读取TXT有误,请大家帮帮忙!
- DateTable 的 Select方法能否查询1个时间在一个时间段内?Between
- 请教全角 半角 的转换
- 菜鸟求助
- C#如何操作IIS,检查一个站点的虚拟目录是否存在?在虚拟目录下新建虚拟目录及其修改和删除???不要让小妹被老板炒了啊!帮个忙哦!
- 向ACCESS数据库中增加记录的函数,大家是否也返回自动编号值?
- 呕出几十两血支持中国女足和男篮小散分
- 在VS里有Toghter时,不小心删除了工具栏里UML Use Case 选项卡,我怎么恢复呢~~
- WebService和.Net Remoting 的区别?
ConfigurationSettings.AppSettings ["CollectCycle"];
2.
NameValueCollection nvc = (NameValueCollection) ConfigurationSettings.GetConfig("TempFolder");
if(nvc["TempFolder"] != null && nvc["TempFolder"] != "")
filePath = nvc["TempFolder"];
[App setting] ............这是Section
Name = App ............这是Setting, Key="Name", value = "App"
Author = ChenMoZhiLang;
...GetPrivateProfileInt();
GetPrivateProfileString();
GetPrivateProfileSection();
WritePrivateProfileSection();
WritePrivateProfileString();
GetPrivateProfileSectionNames();
使用方法
[DllImport("Kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
[DllImport("Kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
lucida.ConnectionString
在WEB。CONFIG
<add key="A" value="config with A"/>
<add key="B" value="config with B"/>
</appSettings> using System.Configuration;[A] 方法string strTest = ConfigurationSettings.AppSettings["A"]; // get A 's value[B] 方法AppSettingsReader appReader = new AppSettingsReader();
string strTest = appReader.GetValue(strKey,typeof(string)).ToString();e.g.private string GetConfig(string strKey)
{
AppSettingsReader appReader = new AppSettingsReader();
string strReturn;
try
{
strReturn = appReader.GetValue(strKey,typeof(string)).ToString();
}
catch(Exception ex)
{
strReturn = ex.Message.ToString();
}
finally
{
appReader = null;
}
return strReturn;
}