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?

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

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.
Avatar of jazzIIIlove

ASKER

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.
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/
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.
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?
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.
ASKER CERTIFIED SOLUTION
Avatar of Daniel Van Der Werken
Daniel Van Der Werken
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.