在C#中,每当我需要获得文件的路径更dyanmically,我做这样的事情文件路径在XML文件中
string filePath = System.IO.Path.GetFullPath(@"..\..\TestData\TestFile.xls");
反正是有,我可以提xml文件相同的文件路径。
<ConfigValue name ="filePath" value="<filepath like above>"/>
在C#中,每当我需要获得文件的路径更dyanmically,我做这样的事情文件路径在XML文件中
string filePath = System.IO.Path.GetFullPath(@"..\..\TestData\TestFile.xls");
反正是有,我可以提xml文件相同的文件路径。
<ConfigValue name ="filePath" value="<filepath like above>"/>
您可以将它添加到您的应用程序/ web.config中
string filePath = ConfigurationManager.AppSettings["filePath"];
你需要一个using语句添加到文件的顶部:
using System.Configuration;
而要做到这工作,你需要参考您的工程中的添加到System.Configuration
总成吨。
什么是与
<ConfigValue name ="filePath" value="..\..\TestData\TestFile.xls"/>
问题?像这样
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="filePath" value="yourPath" />
</appSettings>
...
</configuration>
还要读值:
谢谢,但它没有奏效。 – sanjeev40084 2010-04-08 14:26:57
lkaso的建议包含有效的xml,因此问题可能与您阅读的方式相同。你能提供你想要完成的更多细节吗? – Todd 2010-04-08 14:33:15
什么没有工作?你期望什么?请添加您的代码。 – Ikaso 2010-04-08 14:33:36
我没有从web.config中读取值到主应用程序。 – sanjeev40084 2010-04-08 15:58:13
@ sanjeev40084为什么不呢?那怎么不是一种选择?这是存储配置值的正确位置。 – 2010-04-08 16:49:35