473,465 Members | 1,444 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Access Web.Config from a Console / Windows application

I have a solution that comprises a web based project and a console
application. Web.Config holds attributes that I want to access from my
console application, can anyone advise me as to how to do this?

Restructuring the project to put the values into a database is not an
option.

Is there someway of invoking a web context to allow access to web.config
or should I use a FileStream and read web.config into an xml doc and
parse? If so does any one have any examples of the xml?

Many thanks.

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
4 8598
Hi Chris,

Reading and parsing the XML file seems like the best idea. You can use the
code below to do it, it's taken from a CF app but it does what you want.

XmlDocument xSettings = new XmlDocument();

xSettings.Load(new System.IO.StreamReader(configPath));

foreach(XmlNode node in xSettings["configuration"]["appSettings"])

{

switch(node.Attributes["key"].Value)

{

case "RASEntryName":

node.Attributes["value"].Value = entryName;

break;

case "RASPhoneNumber":

node.Attributes["value"].Value = phoneNumber;

break;

case "RASUsername":

node.Attributes["value"].Value = userName;

break;

case "RASPassword":

node.Attributes["value"].Value = password;

break;
Cheers,

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

"christopher green" <us************@yahoo.com> wrote in message
news:uZ****************@TK2MSFTNGP09.phx.gbl...
I have a solution that comprises a web based project and a console
application. Web.Config holds attributes that I want to access from my
console application, can anyone advise me as to how to do this?

Restructuring the project to put the values into a database is not an
option.

Is there someway of invoking a web context to allow access to web.config
or should I use a FileStream and read web.config into an xml doc and
parse? If so does any one have any examples of the xml?

Many thanks.

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #2
System.Configuration.ConfigurationSettings.AppSett ings["conn_string"].ToString()
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 16 '05 #3
Hi,

I don';t think that using this the config of the web application can be
accessed from the console application. You use that construct to access your
own config values, not those of another applucation

Cheers,

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

"bhargav" <bh************@rediffmail-dot-com.no-spam.invalid> wrote in
message news:40**********@Usenet.com...
System.Configuration.ConfigurationSettings.AppSett ings["conn_string"].ToStri
ng()

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Nov 16 '05 #4
Ignacio, your xml solution is just what I need, thanks.

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #5

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

Similar topics

0
by: helpSeekar | last post by:
I wrote a small application. I created config file as ConsoleApplication1.exe.config. 1. I have appsettings section. <configuration> <appSettings> <add key="Application Name"...
10
by: Clint | last post by:
Hey all - I'm having a really confusing problem concerning a web service. Right now, I have an application that needs to call a web service that does nothing but return "true" (this will...
2
by: Vaap | last post by:
I did lot of googling to see if I can solve the SQL server not found problem while trying to run ASP.Net community starter kit from an XP machine to Windows 2003 server hosting SQL server 2000...
29
by: Patrick | last post by:
I have the following code, which regardless which works fine and logs to the EventViewer regardless of whether <processModel/> section of machine.config is set to username="SYSTEM" or "machine" ...
6
by: daver | last post by:
Hello all, I am running IIS 5.1 on Windows XP professional. I am writing a web application in C# with Visual Studio.NET. I would like to populate various data structures in my web application...
5
by: Sridhar | last post by:
Hi, I have created a project which contains classes to read the data from the database. This project has an App.Config file which contains the SqlConnection String. when this code is called from...
5
by: Keith | last post by:
Hello all, I have a C# Windows Forms app. It is in namespace App.GUI. It builds to Nav.exe. I have entered an application level setting using the designer. Its type is string, name is "FOO"...
7
by: =?Utf-8?B?RG91Z2llIEJyb3du?= | last post by:
Hi I've written custom configuration section (inherits from System.Configuration.ConfigurationSection) to simplify the contents of the config file and to make life easier when accessing them in...
6
by: Peted | last post by:
Hi, im wanting to store some custom text strings in the app.config file of a c# app, to be retreived and updated when the app runs. using c# 2005 express in my testing i am using the code...
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
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
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...
1
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.