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?

C#ASP.NET.NET Programming

Avatar of undefined
Last Comment

8/22/2022 - Mon
Daniel Van Der Werken

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.

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?

Daniel Van Der Werken

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:

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy

Above is not totally helping..Ah, the problem is actually like this.


What should i do for web.config file?

Daniel Van Der Werken

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?

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Daniel Van Der Werken

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question


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?