In C#, Whenever i need to get file path more dyanmically, i do something like this
string filePath = System.IO.Path.GetFullP开发者_JAVA百科ath(@"..\..\TestData\TestFile.xls");
Is there anyway, i can mention same file path in xml file.
<ConfigValue name ="filePath" value="<filepath like above>"/>
You can add this to your app/web.config:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="filePath" value="yourPath" />
</appSettings>
...
</configuration>
And read the value like so:
string filePath = ConfigurationManager.AppSettings["filePath"];
You need to add a using statement to the top of your file:
using System.Configuration;
And for that to work you need to add a reference to the System.Configuration
assembly in your project.
精彩评论