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?

Regards.
C#ASP.NET.NET Programming

Avatar of undefined
Last Comment
jazzIIIlove

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:

http://msdn.microsoft.com/en-us/library/system.io.directory.getcurrentdirectory(v=vs.100).aspx

However, that might not do it. You could also check out:
http://msdn.microsoft.com/en-us/library/system.reflection.assembly.getexecutingassembly(v=vs.100).aspx

Regardless, there should be something that meets your needs.
ASKER
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?

Regards.
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:

http://msdn.microsoft.com/en-us/library/4c2kcht0(v=vs.85).aspx

This is an example:

http://www.dotnetperls.com/appsettings

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

http://msmvps.com/blogs/simpleman/archive/2005/06/23/54733.aspx

and here too:

http://blog.itsyssolutions.com/modify-webconfig-file-programmatically-at-runtime/
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
ASKER
jazzIIIlove

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

http://stackoverflow.com/questions/7712450/how-to-pass-relative-path-in-appsetting

What should i do for web.config file?

Regards.
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?
ASKER
jazzIIIlove

Hi;

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?

Regards.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
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
or
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
ASKER
jazzIIIlove

Hi;

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?

Regards.