tags:

views:

51

answers:

2

In C#, Whenever i need to get file path more dyanmically, i do something like this

string filePath = System.IO.Path.GetFullPath(@"..\..\TestData\TestFile.xls");

Is there anyway, i can mention same file path in xml file.

<ConfigValue name ="filePath" value="<filepath like above>"/>
A: 

What's the problem with
<ConfigValue name ="filePath" value="..\..\TestData\TestFile.xls"/>?

Ikaso
thanks but it didn't work.
sanjeev40084
lkaso's suggestion contains valid xml, so maybe the problem is in the way you are reading it. Can you provide more detail about what you're trying to accomplish?
Todd Benning
What didn't work? What did you expect? Please add your code.
Ikaso
+2  A: 

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.

klausbyskov
i am not reading value from web.config to the main applicaiton.
sanjeev40084
@sanjeev40084 Why not? How come that is not an option? It's the right place to store configuration values.
klausbyskov