Link to home
Start Free TrialLog in
Avatar of jazzIIIlove
jazzIIIloveFlag for Sweden

asked on

Trying to set a valid path in Application Configuration in web.config of ASP.NET (same as C#)

Hi there;

I am trying to set a valid path value for Application Configuration in web.config of ASP.NET

I have a key which has a value as this:

<add key="foo" value="C:/baz/my/project/path/bar>

Open in new window

The thing is when I copy my project to another machine, it has no baz directory but my/project/path/bar directory since it's the project path itself. So, i need to refer a generic solution in web.config file.

What to do?

Avatar of Daniel Van Der Werken
Daniel Van Der Werken
Flag of United States of America image

The .NET Framework comes with a bunch of different methods you can use to get the path relative to the running application. The one you might be interested in here is this:

However, that might not do it. You could also check out:

Regardless, there should be something that meets your needs.
Avatar of jazzIIIlove


Ah, i guess you misunderstood me.

I need to change the web.xml, not the calling code.

I was asking what i should write as a value in web.config.

add key="var" value="stg generic reflecting the project base"

In my xml, there is the baz folder which works fine in my local machine but fails for remote machine since baz is not part of the project structure.

What to do in config file?

I did misunderstand. This isn't something you typically do, but it appears to be something that other have needed doing too:

This is an example:

I just realized these might not show how to SET the values. Here is an example:

and here too:
Above is not totally helping..Ah, the problem is actually like this.

What should i do for web.config file?

I looked at the Stack Overflow post, but I am now less sure of what you want. At first, I thought you wanted the ability to find out which directory the application was running from. Then, I thought you wanted the ability to modify a setting in the web.config programmatically. Now, I'm not sure what you want. Can you provide more specifics?

Maybe explain what you're trying to do, exactly?

My mistake, I create a confusion i think.

What I want is that I need to set a relative path for my project in my web.config in xml. What is the way for this?

Avatar of Daniel Van Der Werken
Daniel Van Der Werken
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

You really brute force, thank you. :)

in web.config, may i?
<add key="foo" value="~/my/project/path/bar>

where my is the first subfolder in the project?