PC Review


Reply
Thread Tools Rate Thread

app.config again

 
 
Alan T
Guest
Posts: n/a
 
      25th Jul 2006
I have a string inside this file would like to retrieve out.
How do I get that?


 
Reply With Quote
 
 
 
 
PandaGoat@gmail.com
Guest
Posts: n/a
 
      25th Jul 2006

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.

 
Reply With Quote
 
simida
Guest
Posts: n/a
 
      25th Jul 2006
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.AppSettings["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?


 
Reply With Quote
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      25th Jul 2006
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.AppSettings["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" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
>I have a string inside this file would like to retrieve out.
> How do I get that?
>



 
Reply With Quote
 
Alan T
Guest
Posts: n/a
 
      26th Jul 2006
Yes, I am developing with VS2005.
I tried
System.Configuration.ConfigurationSettings.AppSettings["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:eJuxwj%(E-Mail Removed)...
> 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.AppSettings["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" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>>I have a string inside this file would like to retrieve out.
>> How do I get that?
>>

>
>



 
Reply With Quote
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      26th Jul 2006
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" <(E-Mail Removed)> wrote in message
news:eB%(E-Mail Removed)...
> Yes, I am developing with VS2005.
> I tried
> System.Configuration.ConfigurationSettings.AppSettings["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:eJuxwj%(E-Mail Removed)...
>> 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.AppSettings["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" <(E-Mail Removed)> wrote in message
>> news:%(E-Mail Removed)...
>>>I have a string inside this file would like to retrieve out.
>>> How do I get that?
>>>

>>
>>

>
>



 
Reply With Quote
 
Alan T
Guest
Posts: n/a
 
      27th Jul 2006
<?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?



 
Reply With Quote
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      27th Jul 2006
Hi,

Add a <AppSettings> section 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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> <?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?

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dll config and web.config and Label Expressions (binding label text to dll config settings) CSharpner Microsoft ASP .NET 0 9th Apr 2007 10:00 PM
DTDs for machine.config, web.config, security.config available ? =?Utf-8?B?UGF1bCBLZW5uZWR5?= Microsoft Dot NET Framework 1 5th Feb 2007 05:42 AM
sharedListeners config in app.config file doesn't recognize customlocation attribute RJ Microsoft Dot NET 0 1st Nov 2006 08:48 PM
using ReadXml to read exe.config file into Grid and update the exe.config using WriteXml hazz Microsoft C# .NET 0 7th Jul 2006 10:32 PM
Configuration Error - c:\winnt\microsoft.net\framework\v1.1.4322\Config\machine.config Ivan Microsoft ASP .NET 1 21st May 2004 05:18 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:59 PM.