开发者

FilePath in xml file

开发者 https://www.devze.com 2022-12-25 21:41 出处:网络
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\");

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消