朱丽叶(Juliet)的答案是正确的,但仅供参考,您还可以.config
通过web.config
如下设置来在外部文件中添加其他配置:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="DocTabMap" type="System.Configuration.NameValueFileSectionHandler, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<DocTabMap file="CustomDocTabs.config" />
</configuration>
然后,您的CustomDocTabs.config
外观如下所示:
<?xml version="1.0"?>
<DocTabMap>
<add key="A" value="1" />
<add key="B" value="2" />
<add key="C" value="3" />
<add key="D" value="4" />
</DocTabMap>
现在,您可以通过以下代码访问它:
NameValueCollection DocTabMap = ConfigurationManager.GetSection("DocTabMap") as NameValueCollection;
DocTabMap["A"]