首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

100分悬赏:怎么自定义使用config文件

2012-03-18 
100分悬赏:如何自定义使用config文件像Discuz里面大量使用config文件一样给相关实例参考的即送分 ; 不是要

100分悬赏:如何自定义使用config文件
像Discuz 里面大量使用config文件一样  

给相关实例参考的 即送分 ; 不是要怎么操作xml的,这个我会,谢谢了

[解决办法]

<?xml version="1.0" encoding= "utf-8" ?>

<configuration>

<appSettings>

<add key="DatabasePath" value="c:\\projects\data\spider.mdb" />

<add key="SupportEmail" value="webmaster-1@dotnetspider.com" />

</appSettings>

</configuration>

==========================================================================
.net 2.0 providing access method 
string dbPath = 
System.Configuration.ConfigurationSettings.AppSettings["DatabasePath"];
string email = 
System.Configuration.ConfigurationSettings.AppSettings["SupportEmail"];
==========================================================================
[解决办法]
把config做成实体
然后读取的时候序列化为实体,就可以了.

返回类型转为自己的实体

public static object Load(Type type, string filename)
{
FileStream fs = null;
try
{
// open the stream...
fs = new FileStream(GetMapPath(filename), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
XmlSerializer serializer = new XmlSerializer(type);
return serializer.Deserialize(fs);
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (fs != null)
fs.Close();
}
}


<SiteConfigInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SiteName>网站名称</SiteName>
</SiteConfigInfo>


 public class SiteConfigInfo
{
private string siteName;

public string SiteName
{
get { return siteName; }
set { siteName = value; }
}
}

热点排行