开发者

FilePath in xml file

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜