473,397 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Locating application config file

Hi - I would like to load other files relative to the application config
file.

Do anyone know if this is possible?

If I do Environment.CurrentDirectory it will work if the program is launched
directly from there. Another approach is to combine CurrentDirectory with
the CommandLine string in order to locate the startup assembly, and thus the
directory of the application config file.

It all seems very clumsy to me and I am not even sure that'll work very well
in an ASP.NET application.

I wonder if anyone knows of a better technique.

Cheers
Thomas Koch
Nov 15 '05 #1
4 1857
ConfigurationSettings.AppSettings.Item("connectStr ing").ToString) - Will get
you

This value in the Config file

<appSettings>

<add key="connectString" value="packet size=4096;integrated
security=SSPI;data source=-----SQLSRV;persist security info=False;initial
catalog=-----" />

<add key="url" value="http://www.inf-------.com" />
</appSettings>

"Thomas Koch" <th********@yahoo.dk> wrote in message
news:OR**************@TK2MSFTNGP12.phx.gbl...
Hi - I would like to load other files relative to the application config
file.

Do anyone know if this is possible?

If I do Environment.CurrentDirectory it will work if the program is launched directly from there. Another approach is to combine CurrentDirectory with
the CommandLine string in order to locate the startup assembly, and thus the directory of the application config file.

It all seems very clumsy to me and I am not even sure that'll work very well in an ASP.NET application.

I wonder if anyone knows of a better technique.

Cheers
Thomas Koch

Nov 15 '05 #2
Hi Thomas,

In a windows form application you can use.
System.Reflection.Assembly.GetExecutingAssembly(). GetName().Location

it give you the directory of the running assembly. It the current assembly
is located on other directory than the main application then you have to use
another approach, maybe using AppDomain?

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Thomas Koch" <th********@yahoo.dk> wrote in message
news:OR**************@TK2MSFTNGP12.phx.gbl...
Hi - I would like to load other files relative to the application config
file.

Do anyone know if this is possible?

If I do Environment.CurrentDirectory it will work if the program is launched directly from there. Another approach is to combine CurrentDirectory with
the CommandLine string in order to locate the startup assembly, and thus the directory of the application config file.

It all seems very clumsy to me and I am not even sure that'll work very well in an ASP.NET application.

I wonder if anyone knows of a better technique.

Cheers
Thomas Koch

Nov 15 '05 #3
Hi - yes I could insert a key value pair which pointed to the location.

However I am building framework software, which is utilizing the application
config file to contain a deployment descriptor. From this deployment
descriptor I need to point to another file, which is usually located
relative to the application config file.

Since I would very much like to offer a "path-independent" format of the
descriptor, so that the user can just move to another path and still have
the refenrece to this other file working.

Cheers
Thomas

"William Ryan" <do********@comcast.nospam.net> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
ConfigurationSettings.AppSettings.Item("connectStr ing").ToString) - Will get you

This value in the Config file

<appSettings>

<add key="connectString" value="packet size=4096;integrated
security=SSPI;data source=-----SQLSRV;persist security info=False;initial
catalog=-----" />

<add key="url" value="http://www.inf-------.com" />
</appSettings>

"Thomas Koch" <th********@yahoo.dk> wrote in message
news:OR**************@TK2MSFTNGP12.phx.gbl...
Hi - I would like to load other files relative to the application config
file.

Do anyone know if this is possible?

If I do Environment.CurrentDirectory it will work if the program is

launched
directly from there. Another approach is to combine CurrentDirectory with the CommandLine string in order to locate the startup assembly, and thus

the
directory of the application config file.

It all seems very clumsy to me and I am not even sure that'll work very

well
in an ASP.NET application.

I wonder if anyone knows of a better technique.

Cheers
Thomas Koch


Nov 15 '05 #4
Hi Igancio - thanks for the tip on the AppDomain.

It turns out that apparently the AppDomain.CurrentDomain.BaseDirectory
points to the correct directory regardless of running an exe applicatoin or
an ASP.NET

Cheers
Thomas

"Ignacio Machin" <ignacio.machin AT dot.state.fl.us> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi Thomas,

In a windows form application you can use.
System.Reflection.Assembly.GetExecutingAssembly(). GetName().Location

it give you the directory of the running assembly. It the current assembly
is located on other directory than the main application then you have to use another approach, maybe using AppDomain?

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Thomas Koch" <th********@yahoo.dk> wrote in message
news:OR**************@TK2MSFTNGP12.phx.gbl...
Hi - I would like to load other files relative to the application config
file.

Do anyone know if this is possible?

If I do Environment.CurrentDirectory it will work if the program is

launched
directly from there. Another approach is to combine CurrentDirectory with the CommandLine string in order to locate the startup assembly, and thus

the
directory of the application config file.

It all seems very clumsy to me and I am not even sure that'll work very

well
in an ASP.NET application.

I wonder if anyone knows of a better technique.

Cheers
Thomas Koch


Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: grs | last post by:
Can a class library have a app.config file. Reason for asking is that the microsoft application blocks all read from myApp.exe.config. How can you use the application blocks if you do not have an...
1
by: J. Babe | last post by:
I've built an ASP.NET application. I have built a .DLL (VB.NET classes) that handles the database transactions. The web page then gets data via the VB.NET DLL. I am having trouble with the...
0
by: Johann Blake | last post by:
I'm having trouble grasping how ASP.NET correctly locates resources. There is plenty of documentation on this subject but some things are not clear at all. In my ASP.NET application, I have...
2
by: John L. | last post by:
Hi, suppose I have the following in my configuration, <configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <probing privatePath="bin"/> </assemblyBinding>...
6
by: yaron | last post by:
Hi all, I want to give a sample console application for the user with 2 configuration files. I want to give also a 2 .bat files for running the sample application, one for each configuration...
1
by: Shiraz | last post by:
Hi It seems like none of the old posts get any follow up after a few messages, whether or not something constructive comes out of them, so I'm left with no choice but to repost an earlier...
0
by: Ralf | last post by:
Hi, I have the following problem: we have our application spread over two folders Folder1: main.dll (managed cpp assembly, strong named) ... many many resources for main.dll Folder2:...
4
by: jobs | last post by:
Works great on my client when I test from vs.net 2005. Howevever, when I deploy to the web server, I get this error: remotely and local from the web server. An error has occurred while...
4
by: Author | last post by:
This is regarding VS2005-generated files. I've searched a little and found out that *.vshost.* files are VS2005 generated for debugging purpose and should not be published to the end user. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.