473,395 Members | 1,696 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,395 software developers and data experts.

app.config again

I have a string inside this file would like to retrieve out.
How do I get that?
Jul 25 '06 #1
7 1982

Alan T wrote:
I have a string inside this file would like to retrieve out.
How do I get that?
I have a class that I wrote to save settings in a file. I use a method
that similar to this.

string[] file = File.ReadAllLines(filepath);

// Search each line of the file for the one I want
for(int i = 0; i < file.Length; i++)
{
if(file[i] == "stringiwant")
{
break;
}

}
This is simple example and has really no usability, but it gives you
the idea. If you would like the code to what I wrote then e-mail me.

Jul 25 '06 #2
In app.config, you have some configurations as follows,

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="IpAddress" value="10.255.20.213"/>
<add key="Port" value="8088"/>
</appSettings>
</configuration>

Now , you can get the string like this,

string ipAddress =
System.Configuration.ConfigurationSettings.AppSett ings["IpAddress"];

result : ipAddress = "10.255.20.213";

Useful for you?

Alan T wrote:
I have a string inside this file would like to retrieve out.
How do I get that?
Jul 25 '06 #3
Hi,

The app.config file is a XML file with a defined structure, you have classes
in the framework ( System.Configuration ) that deals with this file in an
easy way.

Usually you define your settings inside the <AppSettings section. in this
case you can use
Syste,Configuration.ConfigurationSettings.AppSetti ngs["YoueKey"] to retrieve
it.
Now if you are working with 2.0 the above code will give you a warning, this
is cause there is a new configuraiton mechanism in place and
ConfigurationSettings is marked as deprecated.

There is an article in MSDN that explain in details the differences between
1.1 and 2.0 refering the config. Unfortunately I cannot find it now :(

--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Alan T" <al*************@yahoo.com.auwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>I have a string inside this file would like to retrieve out.
How do I get that?

Jul 25 '06 #4
Yes, I am developing with VS2005.
I tried
System.Configuration.ConfigurationSettings.AppSett ings["YourKey"];

But there was an error saying something like the "ConfigurationSettings" not
known or something else.

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.uswrote
in message news:eJ****************@TK2MSFTNGP02.phx.gbl...
Hi,

The app.config file is a XML file with a defined structure, you have
classes in the framework ( System.Configuration ) that deals with this
file in an easy way.

Usually you define your settings inside the <AppSettings section. in
this case you can use
Syste,Configuration.ConfigurationSettings.AppSetti ngs["YoueKey"] to
retrieve it.
Now if you are working with 2.0 the above code will give you a warning,
this is cause there is a new configuraiton mechanism in place and
ConfigurationSettings is marked as deprecated.

There is an article in MSDN that explain in details the differences
between 1.1 and 2.0 refering the config. Unfortunately I cannot find it
now :(

--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Alan T" <al*************@yahoo.com.auwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>>I have a string inside this file would like to retrieve out.
How do I get that?


Jul 26 '06 #5
Hi,

Can you post your config file?

also what kind of project is this? remember than the dll has no default
config file associated.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Alan T" <al*************@yahoo.com.auwrote in message
news:eB****************@TK2MSFTNGP05.phx.gbl...
Yes, I am developing with VS2005.
I tried
System.Configuration.ConfigurationSettings.AppSett ings["YourKey"];

But there was an error saying something like the "ConfigurationSettings"
not known or something else.

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
wrote in message news:eJ****************@TK2MSFTNGP02.phx.gbl...
>Hi,

The app.config file is a XML file with a defined structure, you have
classes in the framework ( System.Configuration ) that deals with this
file in an easy way.

Usually you define your settings inside the <AppSettings section. in
this case you can use
Syste,Configuration.ConfigurationSettings.AppSett ings["YoueKey"] to
retrieve it.
Now if you are working with 2.0 the above code will give you a warning,
this is cause there is a new configuraiton mechanism in place and
ConfigurationSettings is marked as deprecated.

There is an article in MSDN that explain in details the differences
between 1.1 and 2.0 refering the config. Unfortunately I cannot find it
now :(

--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Alan T" <al*************@yahoo.com.auwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>>>I have a string inside this file would like to retrieve out.
How do I get that?



Jul 26 '06 #6
<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<configSections>

<sectionGroup name="userSettings"
type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e999" >

<section name="ApplicationLogin.AppLogin"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e999"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />

</sectionGroup>

</configSections>

</configuration>

What I want to do is to store a database connection string in this file and
read that out when the progam starts.
Can you post your config file?

Jul 27 '06 #7
Hi,

Add a <AppSettingssection to the file, then you can use the classes from
Configuration namespace to read the values back.

It seems like a 2.0 file so you use ConfigurationManager.AppSettings also be
aware of a new section in the config file ConnectionStrings and a property
for it ConfigurationManager.AppSettings

I know there is an article in MSDN explaining the new features of the
Configuration in 2.0 , maybe somebody can post a link here.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Alan T" <al*************@yahoo.com.auwrote in message
news:OU**************@TK2MSFTNGP02.phx.gbl...
<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<configSections>

<sectionGroup name="userSettings"
type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e999" >

<section name="ApplicationLogin.AppLogin"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e999"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />

</sectionGroup>

</configSections>

</configuration>

What I want to do is to store a database connection string in this file
and read that out when the progam starts.
>Can you post your config file?


Jul 27 '06 #8

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

Similar topics

5
by: Tom Willis | last post by:
How are the expert pythoneers dealing with config files? Is there anything similair to .net's config files or java's .properties? A quick search on google didn't return anything that looked...
2
by: Scanner2001 | last post by:
I have a service with settings in the app.config file. I would like to be able to change these settings without restarting the service. Something similar to a web.config with web services. Whenever...
1
by: Rolf Molini | last post by:
Hello everybody, I put this in a separate thread because altough it is connected to the localization-problem in my former thread this is a completely different "joke" of the IDE. While waiting...
5
by: AAguiar | last post by:
I have an asp.net project where the code behind the aspx page calls a c# class which makes calls to a managed static C++ class. The C# class works fine when the asp net worker process starts, when...
6
by: Mikey_Doc | last post by:
Hi We are running cms 2002, Framework 1.0 with Visual studio 2002. We have just upgraded to Framework 1.1 and visual studio 2003. All of our database connection strings are stored within the...
5
by: feng | last post by:
Hi, We just converted our VB.Net Windows exe project from VS.Net 2002 to VS.Net 2003 and ran into a problem. the MyApp.exe.config file that we use for our customized configuration settings is...
13
by: Khodr | last post by:
Hello, I am using VS.NET 2003 and vb. I build my application MyApp and it generates MyApp.exe.config. So now MyApp.exe reads parameters from MyApp.exe.config. Great and no problem! I need to...
17
by: Fred Nelson | last post by:
Hi: I have written several web applications that obtain their connection strings from the web.config file. This is very easy to use and it makes it easy to move an app from development into...
0
by: df | last post by:
I'm seeing a strange problem in the Web App config tool: After creating a role and a user, going back to the Security tab home page, I get a "Specified cast is not valid" error. I've set up my...
6
by: Irfan | last post by:
hi, After installing the application in the client machine using ClickOnce, i would like that the client be able to change the database path in the Application.Config file. However, clickonce...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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.