473,791 Members | 2,711 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using XML to store global variables in memory

now in my web I have some global variables to be used in many different
subpages, in the old ASP I simply loaded a variables.asp file into memory
using the eval() function. Now I'd like to use XML but what method would I
use to load the entries from the xml file into memory and make them quickly
accessible globally in the web code? Just need to know what functions
specifically I should start reading about!

Thx
Nov 18 '05
17 2462
Kevin, so far so good but .Net doesn't allow me to split the appsettings
into subgroups eg
<appSettings>
<Web1Group>
<add key="Title" value="Title of web 1"/>
...
</Web1Group>
<Web2Group>
<add key="Title" value="Title of web 2"/>
...
</Web2Group>
</appSettings>

The error I get: "Unrecogniz ed element."

"Kevin Spencer" <ks******@takem pis.com> wrote in message
news:uv******** *****@TK2MSFTNG P15.phx.gbl...
My apologies, David.

After re-reading your question and my response, I can see that I was not
answering the question you asked, which is how to read data stored in an
XML
file INTO memory, which is something altogether different from storing XML
data IN memory. Reading it from a file is a great idea, as exemplified by
the use of XML for the web.config and other configuration files that
ASP.Net
and .Net in general uses.

In fact, using the web.config file might be your best bet to begin with.
You
can easily use the built-in "appSetting s" element in the web.config to
define your own data, which can easily be read from the file at run time.
Example:

<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<appSettings>
<add key="Connection String"
value="server=b lah;uid=Blah;pw d=blahblah;data base=blah"/>
<add key="VoyagerPat h" value="C:\Voyag erOnline" />
<add key="Timeout" value="15" />
</appSettings>
...

These configuration elements are easy to fetch at run-time. Example:

Dim Timeout As int =
System.Configur ation.Configura tionSettings.Ap pSettings("Time out")

You can also define custom configuration sections, if you have a lot of
data
and need to organize it into a nice tree hierarchy.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Davíð Þórisson" <db**@hi.is> wrote in message
news:eh******** *****@TK2MSFTNG P11.phx.gbl...
now in my web I have some global variables to be used in many different
subpages, in the old ASP I simply loaded a variables.asp file into memory
using the eval() function. Now I'd like to use XML but what method would
I
use to load the entries from the xml file into memory and make them

quickly
accessible globally in the web code? Just need to know what functions
specifically I should start reading about!

Thx


Nov 18 '05 #11
Correct. Remember I mentioned that you can create your own customized
Sections? That's what you need here. See the following SDK article for more
information about how:

http://msdn.microsoft.com/library/de...tiongroups.asp

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Davíð Þórisson" <db**@hi.is> wrote in message
news:ez******** ******@tk2msftn gp13.phx.gbl...
Kevin, so far so good but .Net doesn't allow me to split the appsettings
into subgroups eg
<appSettings>
<Web1Group>
<add key="Title" value="Title of web 1"/>
...
</Web1Group>
<Web2Group>
<add key="Title" value="Title of web 2"/>
...
</Web2Group>
</appSettings>

The error I get: "Unrecogniz ed element."

"Kevin Spencer" <ks******@takem pis.com> wrote in message
news:uv******** *****@TK2MSFTNG P15.phx.gbl...
My apologies, David.

After re-reading your question and my response, I can see that I was not
answering the question you asked, which is how to read data stored in an
XML
file INTO memory, which is something altogether different from storing XML data IN memory. Reading it from a file is a great idea, as exemplified by the use of XML for the web.config and other configuration files that
ASP.Net
and .Net in general uses.

In fact, using the web.config file might be your best bet to begin with.
You
can easily use the built-in "appSetting s" element in the web.config to
define your own data, which can easily be read from the file at run time. Example:

<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<appSettings>
<add key="Connection String"
value="server=b lah;uid=Blah;pw d=blahblah;data base=blah"/>
<add key="VoyagerPat h" value="C:\Voyag erOnline" />
<add key="Timeout" value="15" />
</appSettings>
...

These configuration elements are easy to fetch at run-time. Example:

Dim Timeout As int =
System.Configur ation.Configura tionSettings.Ap pSettings("Time out")

You can also define custom configuration sections, if you have a lot of
data
and need to organize it into a nice tree hierarchy.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Davíð Þórisson" <db**@hi.is> wrote in message
news:eh******** *****@TK2MSFTNG P11.phx.gbl...
now in my web I have some global variables to be used in many different
subpages, in the old ASP I simply loaded a variables.asp file into memory using the eval() function. Now I'd like to use XML but what method would I
use to load the entries from the xml file into memory and make them

quickly
accessible globally in the web code? Just need to know what functions
specifically I should start reading about!

Thx



Nov 18 '05 #12
I have to admit this is far beyond my knowledge so I just try to copy &
paste with some common sense... so far I've got the xml file correct but

NameValueCollec tion sampleConfig =
(NameValueColle ction)Configura tionSettings.Ge tConfig("mySect ionGroup/myWeb1");
string strKeyValue = (string)sampleC onfig["Title"];
myLabel.Text = myVar;

just brings on an error (surprise): "The type or namespace name
'NameValueColle ction' could not be found (are you missing a using directive
or an assembly reference?)"
"Kevin Spencer" <ks******@takem pis.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Correct. Remember I mentioned that you can create your own customized
Sections? That's what you need here. See the following SDK article for
more
information about how:

http://msdn.microsoft.com/library/de...tiongroups.asp

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Davíð Þórisson" <db**@hi.is> wrote in message
news:ez******** ******@tk2msftn gp13.phx.gbl...
Kevin, so far so good but .Net doesn't allow me to split the appsettings
into subgroups eg
<appSettings>
<Web1Group>
<add key="Title" value="Title of web 1"/>
...
</Web1Group>
<Web2Group>
<add key="Title" value="Title of web 2"/>
...
</Web2Group>
</appSettings>

The error I get: "Unrecogniz ed element."

"Kevin Spencer" <ks******@takem pis.com> wrote in message
news:uv******** *****@TK2MSFTNG P15.phx.gbl...
> My apologies, David.
>
> After re-reading your question and my response, I can see that I was
> not
> answering the question you asked, which is how to read data stored in
> an
> XML
> file INTO memory, which is something altogether different from storing XML > data IN memory. Reading it from a file is a great idea, as exemplified by > the use of XML for the web.config and other configuration files that
> ASP.Net
> and .Net in general uses.
>
> In fact, using the web.config file might be your best bet to begin
> with.
> You
> can easily use the built-in "appSetting s" element in the web.config to
> define your own data, which can easily be read from the file at run time. > Example:
>
> <?xml version="1.0" encoding="utf-8" ?>
> <configuratio n>
> <appSettings>
> <add key="Connection String"
> value="server=b lah;uid=Blah;pw d=blahblah;data base=blah"/>
> <add key="VoyagerPat h" value="C:\Voyag erOnline" />
> <add key="Timeout" value="15" />
> </appSettings>
> ...
>
> These configuration elements are easy to fetch at run-time. Example:
>
> Dim Timeout As int =
> System.Configur ation.Configura tionSettings.Ap pSettings("Time out")
>
> You can also define custom configuration sections, if you have a lot of
> data
> and need to organize it into a nice tree hierarchy.
>
> --
> HTH,
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> I get paid good money to
> solve puzzles for a living
>
> "Davíð Þórisson" <db**@hi.is> wrote in message
> news:eh******** *****@TK2MSFTNG P11.phx.gbl...
>> now in my web I have some global variables to be used in many
>> different
>> subpages, in the old ASP I simply loaded a variables.asp file into memory >> using the eval() function. Now I'd like to use XML but what method would >> I
>> use to load the entries from the xml file into memory and make them
> quickly
>> accessible globally in the web code? Just need to know what functions
>> specifically I should start reading about!
>>
>> Thx
>>
>>
>
>



Nov 18 '05 #13
If the type cannot be found, one or both of 2 things is happening. Either
you haven't referenced the assembly (DLL), or you haven't added a using
statement to negate the necessity of using the complete NameSpace hierarchy
in your code. The complete NameSpace for NameValueCollec tion is
"System.Collect ions.Specialize d.NameValueColl ection".

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living
"Davíð Þórisson" <db**@hi.is> wrote in message
news:#o******** ******@TK2MSFTN GP12.phx.gbl...
I have to admit this is far beyond my knowledge so I just try to copy &
paste with some common sense... so far I've got the xml file correct but

NameValueCollec tion sampleConfig =
(NameValueColle ction)Configura tionSettings.Ge tConfig("mySect ionGroup/myWeb1"
); string strKeyValue = (string)sampleC onfig["Title"];
myLabel.Text = myVar;

just brings on an error (surprise): "The type or namespace name
'NameValueColle ction' could not be found (are you missing a using directive or an assembly reference?)"
"Kevin Spencer" <ks******@takem pis.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Correct. Remember I mentioned that you can create your own customized
Sections? That's what you need here. See the following SDK article for
more
information about how:

http://msdn.microsoft.com/library/de...tiongroups.asp
--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Davíð Þórisson" <db**@hi.is> wrote in message
news:ez******** ******@tk2msftn gp13.phx.gbl...
Kevin, so far so good but .Net doesn't allow me to split the appsettings into subgroups eg
<appSettings>
<Web1Group>
<add key="Title" value="Title of web 1"/>
...
</Web1Group>
<Web2Group>
<add key="Title" value="Title of web 2"/>
...
</Web2Group>
</appSettings>

The error I get: "Unrecogniz ed element."

"Kevin Spencer" <ks******@takem pis.com> wrote in message
news:uv******** *****@TK2MSFTNG P15.phx.gbl...
> My apologies, David.
>
> After re-reading your question and my response, I can see that I was
> not
> answering the question you asked, which is how to read data stored in
> an
> XML
> file INTO memory, which is something altogether different from storing
XML
> data IN memory. Reading it from a file is a great idea, as
exemplified by
> the use of XML for the web.config and other configuration files that
> ASP.Net
> and .Net in general uses.
>
> In fact, using the web.config file might be your best bet to begin
> with.
> You
> can easily use the built-in "appSetting s" element in the web.config

to > define your own data, which can easily be read from the file at run

time.
> Example:
>
> <?xml version="1.0" encoding="utf-8" ?>
> <configuratio n>
> <appSettings>
> <add key="Connection String"
> value="server=b lah;uid=Blah;pw d=blahblah;data base=blah"/>
> <add key="VoyagerPat h" value="C:\Voyag erOnline" />
> <add key="Timeout" value="15" />
> </appSettings>
> ...
>
> These configuration elements are easy to fetch at run-time. Example:
>
> Dim Timeout As int =
> System.Configur ation.Configura tionSettings.Ap pSettings("Time out")
>
> You can also define custom configuration sections, if you have a lot of > data
> and need to organize it into a nice tree hierarchy.
>
> --
> HTH,
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> I get paid good money to
> solve puzzles for a living
>
> "Davíð Þórisson" <db**@hi.is> wrote in message
> news:eh******** *****@TK2MSFTNG P11.phx.gbl...
>> now in my web I have some global variables to be used in many
>> different
>> subpages, in the old ASP I simply loaded a variables.asp file into

memory
>> using the eval() function. Now I'd like to use XML but what method

would
>> I
>> use to load the entries from the xml file into memory and make them
> quickly
>> accessible globally in the web code? Just need to know what functions >> specifically I should start reading about!
>>
>> Thx
>>
>>
>
>



Nov 18 '05 #14
Kevin
could you kindly email me, I'm so close to getting this done (the using
statement is there) still some error I can't figure out :(
"Kevin Spencer" <ks******@takem pis.com> wrote in message
news:uS******** ******@TK2MSFTN GP14.phx.gbl...
If the type cannot be found, one or both of 2 things is happening. Either
you haven't referenced the assembly (DLL), or you haven't added a using
statement to negate the necessity of using the complete NameSpace
hierarchy
in your code. The complete NameSpace for NameValueCollec tion is
"System.Collect ions.Specialize d.NameValueColl ection".

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living
"Davíð Þórisson" <db**@hi.is> wrote in message
news:#o******** ******@TK2MSFTN GP12.phx.gbl...
I have to admit this is far beyond my knowledge so I just try to copy &
paste with some common sense... so far I've got the xml file correct but

NameValueCollec tion sampleConfig =

(NameValueColle ction)Configura tionSettings.Ge tConfig("mySect ionGroup/myWeb1"
);
string strKeyValue = (string)sampleC onfig["Title"];
myLabel.Text = myVar;

just brings on an error (surprise): "The type or namespace name
'NameValueColle ction' could not be found (are you missing a using

directive
or an assembly reference?)"
"Kevin Spencer" <ks******@takem pis.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
> Correct. Remember I mentioned that you can create your own customized
> Sections? That's what you need here. See the following SDK article for
> more
> information about how:
>
> http://msdn.microsoft.com/library/de...tiongroups.asp >
> --
> HTH,
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> I get paid good money to
> solve puzzles for a living
>
> "Davíð Þórisson" <db**@hi.is> wrote in message
> news:ez******** ******@tk2msftn gp13.phx.gbl...
>> Kevin, so far so good but .Net doesn't allow me to split the appsettings >> into subgroups eg
>> <appSettings>
>> <Web1Group>
>> <add key="Title" value="Title of web 1"/>
>> ...
>> </Web1Group>
>> <Web2Group>
>> <add key="Title" value="Title of web 2"/>
>> ...
>> </Web2Group>
>> </appSettings>
>>
>> The error I get: "Unrecogniz ed element."
>>
>>
>>
>> "Kevin Spencer" <ks******@takem pis.com> wrote in message
>> news:uv******** *****@TK2MSFTNG P15.phx.gbl...
>> > My apologies, David.
>> >
>> > After re-reading your question and my response, I can see that I was
>> > not
>> > answering the question you asked, which is how to read data stored
>> > in
>> > an
>> > XML
>> > file INTO memory, which is something altogether different from storing > XML
>> > data IN memory. Reading it from a file is a great idea, as exemplified > by
>> > the use of XML for the web.config and other configuration files that
>> > ASP.Net
>> > and .Net in general uses.
>> >
>> > In fact, using the web.config file might be your best bet to begin
>> > with.
>> > You
>> > can easily use the built-in "appSetting s" element in the web.config to >> > define your own data, which can easily be read from the file at run
> time.
>> > Example:
>> >
>> > <?xml version="1.0" encoding="utf-8" ?>
>> > <configuratio n>
>> > <appSettings>
>> > <add key="Connection String"
>> > value="server=b lah;uid=Blah;pw d=blahblah;data base=blah"/>
>> > <add key="VoyagerPat h" value="C:\Voyag erOnline" />
>> > <add key="Timeout" value="15" />
>> > </appSettings>
>> > ...
>> >
>> > These configuration elements are easy to fetch at run-time. Example:
>> >
>> > Dim Timeout As int =
>> > System.Configur ation.Configura tionSettings.Ap pSettings("Time out")
>> >
>> > You can also define custom configuration sections, if you have a lot of >> > data
>> > and need to organize it into a nice tree hierarchy.
>> >
>> > --
>> > HTH,
>> > Kevin Spencer
>> > .Net Developer
>> > Microsoft MVP
>> > I get paid good money to
>> > solve puzzles for a living
>> >
>> > "Davíð Þórisson" <db**@hi.is> wrote in message
>> > news:eh******** *****@TK2MSFTNG P11.phx.gbl...
>> >> now in my web I have some global variables to be used in many
>> >> different
>> >> subpages, in the old ASP I simply loaded a variables.asp file into
> memory
>> >> using the eval() function. Now I'd like to use XML but what method
> would
>> >> I
>> >> use to load the entries from the xml file into memory and make them
>> > quickly
>> >> accessible globally in the web code? Just need to know what functions >> >> specifically I should start reading about!
>> >>
>> >> Thx
>> >>
>> >>
>> >
>> >
>>
>>
>
>



Nov 18 '05 #15
Hi David,

I'm afraid I don't help people by email, for a number of reasons too long to
go into here.

I will be happy to continue helping you on this newsgroup, however, if you
can tell me where you're having trouble. the article (and related articles)
should give you what you need to know. The section head for the article I
pointed you to is at:

http://msdn.microsoft.com/library/en...asp?frame=true

but I can also answer any specific questions you may have.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Davíð Þórisson" <db**@hi.is> wrote in message
news:eg******** ******@TK2MSFTN GP11.phx.gbl...
Kevin
could you kindly email me, I'm so close to getting this done (the using
statement is there) still some error I can't figure out :(
"Kevin Spencer" <ks******@takem pis.com> wrote in message
news:uS******** ******@TK2MSFTN GP14.phx.gbl...
If the type cannot be found, one or both of 2 things is happening. Either
you haven't referenced the assembly (DLL), or you haven't added a using
statement to negate the necessity of using the complete NameSpace
hierarchy
in your code. The complete NameSpace for NameValueCollec tion is
"System.Collect ions.Specialize d.NameValueColl ection".

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living
"Davíð Þórisson" <db**@hi.is> wrote in message
news:#o******** ******@TK2MSFTN GP12.phx.gbl...
I have to admit this is far beyond my knowledge so I just try to copy &
paste with some common sense... so far I've got the xml file correct but
NameValueCollec tion sampleConfig =

(NameValueColle ction)Configura tionSettings.Ge tConfig("mySect ionGroup/myWeb1" );
string strKeyValue = (string)sampleC onfig["Title"];
myLabel.Text = myVar;

just brings on an error (surprise): "The type or namespace name
'NameValueColle ction' could not be found (are you missing a using

directive
or an assembly reference?)"
"Kevin Spencer" <ks******@takem pis.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
> Correct. Remember I mentioned that you can create your own customized
> Sections? That's what you need here. See the following SDK article for > more
> information about how:
>
>

http://msdn.microsoft.com/library/de...tiongroups.asp
>
> --
> HTH,
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> I get paid good money to
> solve puzzles for a living
>
> "Davíð Þórisson" <db**@hi.is> wrote in message
> news:ez******** ******@tk2msftn gp13.phx.gbl...
>> Kevin, so far so good but .Net doesn't allow me to split the

appsettings
>> into subgroups eg
>> <appSettings>
>> <Web1Group>
>> <add key="Title" value="Title of web 1"/>
>> ...
>> </Web1Group>
>> <Web2Group>
>> <add key="Title" value="Title of web 2"/>
>> ...
>> </Web2Group>
>> </appSettings>
>>
>> The error I get: "Unrecogniz ed element."
>>
>>
>>
>> "Kevin Spencer" <ks******@takem pis.com> wrote in message
>> news:uv******** *****@TK2MSFTNG P15.phx.gbl...
>> > My apologies, David.
>> >
>> > After re-reading your question and my response, I can see that I was >> > not
>> > answering the question you asked, which is how to read data stored
>> > in
>> > an
>> > XML
>> > file INTO memory, which is something altogether different from

storing
> XML
>> > data IN memory. Reading it from a file is a great idea, as

exemplified
> by
>> > the use of XML for the web.config and other configuration files that >> > ASP.Net
>> > and .Net in general uses.
>> >
>> > In fact, using the web.config file might be your best bet to begin
>> > with.
>> > You
>> > can easily use the built-in "appSetting s" element in the web.config to
>> > define your own data, which can easily be read from the file at
run > time.
>> > Example:
>> >
>> > <?xml version="1.0" encoding="utf-8" ?>
>> > <configuratio n>
>> > <appSettings>
>> > <add key="Connection String"
>> > value="server=b lah;uid=Blah;pw d=blahblah;data base=blah"/>
>> > <add key="VoyagerPat h" value="C:\Voyag erOnline" />
>> > <add key="Timeout" value="15" />
>> > </appSettings>
>> > ...
>> >
>> > These configuration elements are easy to fetch at run-time. Example: >> >
>> > Dim Timeout As int =
>> > System.Configur ation.Configura tionSettings.Ap pSettings("Time out")
>> >
>> > You can also define custom configuration sections, if you have a lot of
>> > data
>> > and need to organize it into a nice tree hierarchy.
>> >
>> > --
>> > HTH,
>> > Kevin Spencer
>> > .Net Developer
>> > Microsoft MVP
>> > I get paid good money to
>> > solve puzzles for a living
>> >
>> > "Davíð Þórisson" <db**@hi.is> wrote in message
>> > news:eh******** *****@TK2MSFTNG P11.phx.gbl...
>> >> now in my web I have some global variables to be used in many
>> >> different
>> >> subpages, in the old ASP I simply loaded a variables.asp file

into > memory
>> >> using the eval() function. Now I'd like to use XML but what method > would
>> >> I
>> >> use to load the entries from the xml file into memory and make them >> > quickly
>> >> accessible globally in the web code? Just need to know what

functions
>> >> specifically I should start reading about!
>> >>
>> >> Thx
>> >>
>> >>
>> >
>> >
>>
>>
>
>



Nov 18 '05 #16
no prob Kevin, I understand.
After some Googling I finally managed to solve this although I don't know at
all why. What I did was changing:
<section name="mySection "
type="System.Co nfiguration.Nam eValueSectionHa ndler,System/>
to:
<section name="mySection "
type="System.Co nfiguration.Nam eValueSectionHa ndler,System,
Version=1.0.330 0.0, Culture=neutral , PublicKeyToken= b77a5c561934e08 9,
Custom=null" />

god knows what that Version bla bla does but it works!!! (I always thought
XML was sooo easy and clean code)

"Kevin Spencer" <ks******@takem pis.com> wrote in message
news:ev******** ******@TK2MSFTN GP11.phx.gbl...
Hi David,

I'm afraid I don't help people by email, for a number of reasons too long
to
go into here.

I will be happy to continue helping you on this newsgroup, however, if
you
can tell me where you're having trouble. the article (and related
articles)
should give you what you need to know. The section head for the article I
pointed you to is at:

http://msdn.microsoft.com/library/en...asp?frame=true

but I can also answer any specific questions you may have.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Davíð Þórisson" <db**@hi.is> wrote in message
news:eg******** ******@TK2MSFTN GP11.phx.gbl...
Kevin
could you kindly email me, I'm so close to getting this done (the using
statement is there) still some error I can't figure out :(
"Kevin Spencer" <ks******@takem pis.com> wrote in message
news:uS******** ******@TK2MSFTN GP14.phx.gbl...
> If the type cannot be found, one or both of 2 things is happening. Either > you haven't referenced the assembly (DLL), or you haven't added a using
> statement to negate the necessity of using the complete NameSpace
> hierarchy
> in your code. The complete NameSpace for NameValueCollec tion is
> "System.Collect ions.Specialize d.NameValueColl ection".
>
> --
> HTH,
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> I get paid good money to
> solve puzzles for a living
>
>
> "Davíð Þórisson" <db**@hi.is> wrote in message
> news:#o******** ******@TK2MSFTN GP12.phx.gbl...
>> I have to admit this is far beyond my knowledge so I just try to copy
>> &
>> paste with some common sense... so far I've got the xml file correct but >>
>> NameValueCollec tion sampleConfig =
>>
> (NameValueColle ction)Configura tionSettings.Ge tConfig("mySect ionGroup/myWeb1" > );
>> string strKeyValue = (string)sampleC onfig["Title"];
>> myLabel.Text = myVar;
>>
>> just brings on an error (surprise): "The type or namespace name
>> 'NameValueColle ction' could not be found (are you missing a using
> directive
>> or an assembly reference?)"
>>
>>
>> "Kevin Spencer" <ks******@takem pis.com> wrote in message
>> news:%2******** ********@tk2msf tngp13.phx.gbl. ..
>> > Correct. Remember I mentioned that you can create your own
>> > customized
>> > Sections? That's what you need here. See the following SDK article for >> > more
>> > information about how:
>> >
>> >
> http://msdn.microsoft.com/library/de...tiongroups.asp >> >
>> > --
>> > HTH,
>> > Kevin Spencer
>> > .Net Developer
>> > Microsoft MVP
>> > I get paid good money to
>> > solve puzzles for a living
>> >
>> > "Davíð Þórisson" <db**@hi.is> wrote in message
>> > news:ez******** ******@tk2msftn gp13.phx.gbl...
>> >> Kevin, so far so good but .Net doesn't allow me to split the
> appsettings
>> >> into subgroups eg
>> >> <appSettings>
>> >> <Web1Group>
>> >> <add key="Title" value="Title of web 1"/>
>> >> ...
>> >> </Web1Group>
>> >> <Web2Group>
>> >> <add key="Title" value="Title of web 2"/>
>> >> ...
>> >> </Web2Group>
>> >> </appSettings>
>> >>
>> >> The error I get: "Unrecogniz ed element."
>> >>
>> >>
>> >>
>> >> "Kevin Spencer" <ks******@takem pis.com> wrote in message
>> >> news:uv******** *****@TK2MSFTNG P15.phx.gbl...
>> >> > My apologies, David.
>> >> >
>> >> > After re-reading your question and my response, I can see that I was >> >> > not
>> >> > answering the question you asked, which is how to read data
>> >> > stored
>> >> > in
>> >> > an
>> >> > XML
>> >> > file INTO memory, which is something altogether different from
> storing
>> > XML
>> >> > data IN memory. Reading it from a file is a great idea, as
> exemplified
>> > by
>> >> > the use of XML for the web.config and other configuration files that >> >> > ASP.Net
>> >> > and .Net in general uses.
>> >> >
>> >> > In fact, using the web.config file might be your best bet to
>> >> > begin
>> >> > with.
>> >> > You
>> >> > can easily use the built-in "appSetting s" element in the web.config > to
>> >> > define your own data, which can easily be read from the file at run >> > time.
>> >> > Example:
>> >> >
>> >> > <?xml version="1.0" encoding="utf-8" ?>
>> >> > <configuratio n>
>> >> > <appSettings>
>> >> > <add key="Connection String"
>> >> > value="server=b lah;uid=Blah;pw d=blahblah;data base=blah"/>
>> >> > <add key="VoyagerPat h" value="C:\Voyag erOnline" />
>> >> > <add key="Timeout" value="15" />
>> >> > </appSettings>
>> >> > ...
>> >> >
>> >> > These configuration elements are easy to fetch at run-time. Example: >> >> >
>> >> > Dim Timeout As int =
>> >> > System.Configur ation.Configura tionSettings.Ap pSettings("Time out")
>> >> >
>> >> > You can also define custom configuration sections, if you have a lot > of
>> >> > data
>> >> > and need to organize it into a nice tree hierarchy.
>> >> >
>> >> > --
>> >> > HTH,
>> >> > Kevin Spencer
>> >> > .Net Developer
>> >> > Microsoft MVP
>> >> > I get paid good money to
>> >> > solve puzzles for a living
>> >> >
>> >> > "Davíð Þórisson" <db**@hi.is> wrote in message
>> >> > news:eh******** *****@TK2MSFTNG P11.phx.gbl...
>> >> >> now in my web I have some global variables to be used in many
>> >> >> different
>> >> >> subpages, in the old ASP I simply loaded a variables.asp file into >> > memory
>> >> >> using the eval() function. Now I'd like to use XML but what method >> > would
>> >> >> I
>> >> >> use to load the entries from the xml file into memory and make them >> >> > quickly
>> >> >> accessible globally in the web code? Just need to know what
> functions
>> >> >> specifically I should start reading about!
>> >> >>
>> >> >> Thx
>> >> >>
>> >> >>
>> >> >
>> >> >
>> >>
>> >>
>> >
>> >
>>
>>
>
>



Nov 18 '05 #17
Aha! Well, there you go. Nice work, David.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Davíð Þórisson" <db**@hi.is> wrote in message
news:u0******** *****@TK2MSFTNG P09.phx.gbl...
no prob Kevin, I understand.
After some Googling I finally managed to solve this although I don't know at all why. What I did was changing:
<section name="mySection "
type="System.Co nfiguration.Nam eValueSectionHa ndler,System/>
to:
<section name="mySection "
type="System.Co nfiguration.Nam eValueSectionHa ndler,System,
Version=1.0.330 0.0, Culture=neutral , PublicKeyToken= b77a5c561934e08 9,
Custom=null" />

god knows what that Version bla bla does but it works!!! (I always thought
XML was sooo easy and clean code)

"Kevin Spencer" <ks******@takem pis.com> wrote in message
news:ev******** ******@TK2MSFTN GP11.phx.gbl...
Hi David,

I'm afraid I don't help people by email, for a number of reasons too long
to
go into here.

I will be happy to continue helping you on this newsgroup, however, if
you
can tell me where you're having trouble. the article (and related
articles)
should give you what you need to know. The section head for the article I pointed you to is at:

http://msdn.microsoft.com/library/en...asp?frame=true
but I can also answer any specific questions you may have.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Davíð Þórisson" <db**@hi.is> wrote in message
news:eg******** ******@TK2MSFTN GP11.phx.gbl...
Kevin
could you kindly email me, I'm so close to getting this done (the using
statement is there) still some error I can't figure out :(
"Kevin Spencer" <ks******@takem pis.com> wrote in message
news:uS******** ******@TK2MSFTN GP14.phx.gbl...
> If the type cannot be found, one or both of 2 things is happening.

Either
> you haven't referenced the assembly (DLL), or you haven't added a using > statement to negate the necessity of using the complete NameSpace
> hierarchy
> in your code. The complete NameSpace for NameValueCollec tion is
> "System.Collect ions.Specialize d.NameValueColl ection".
>
> --
> HTH,
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> I get paid good money to
> solve puzzles for a living
>
>
> "Davíð Þórisson" <db**@hi.is> wrote in message
> news:#o******** ******@TK2MSFTN GP12.phx.gbl...
>> I have to admit this is far beyond my knowledge so I just try to copy >> &
>> paste with some common sense... so far I've got the xml file correct

but
>>
>> NameValueCollec tion sampleConfig =
>>
>

(NameValueColle ction)Configura tionSettings.Ge tConfig("mySect ionGroup/myWeb1"
> );
>> string strKeyValue = (string)sampleC onfig["Title"];
>> myLabel.Text = myVar;
>>
>> just brings on an error (surprise): "The type or namespace name
>> 'NameValueColle ction' could not be found (are you missing a using
> directive
>> or an assembly reference?)"
>>
>>
>> "Kevin Spencer" <ks******@takem pis.com> wrote in message
>> news:%2******** ********@tk2msf tngp13.phx.gbl. ..
>> > Correct. Remember I mentioned that you can create your own
>> > customized
>> > Sections? That's what you need here. See the following SDK article

for
>> > more
>> > information about how:
>> >
>> >
>

http://msdn.microsoft.com/library/de...tiongroups.asp
>> >
>> > --
>> > HTH,
>> > Kevin Spencer
>> > .Net Developer
>> > Microsoft MVP
>> > I get paid good money to
>> > solve puzzles for a living
>> >
>> > "Davíð Þórisson" <db**@hi.is> wrote in message
>> > news:ez******** ******@tk2msftn gp13.phx.gbl...
>> >> Kevin, so far so good but .Net doesn't allow me to split the
> appsettings
>> >> into subgroups eg
>> >> <appSettings>
>> >> <Web1Group>
>> >> <add key="Title" value="Title of web 1"/>
>> >> ...
>> >> </Web1Group>
>> >> <Web2Group>
>> >> <add key="Title" value="Title of web 2"/>
>> >> ...
>> >> </Web2Group>
>> >> </appSettings>
>> >>
>> >> The error I get: "Unrecogniz ed element."
>> >>
>> >>
>> >>
>> >> "Kevin Spencer" <ks******@takem pis.com> wrote in message
>> >> news:uv******** *****@TK2MSFTNG P15.phx.gbl...
>> >> > My apologies, David.
>> >> >
>> >> > After re-reading your question and my response, I can see that I was
>> >> > not
>> >> > answering the question you asked, which is how to read data
>> >> > stored
>> >> > in
>> >> > an
>> >> > XML
>> >> > file INTO memory, which is something altogether different from
> storing
>> > XML
>> >> > data IN memory. Reading it from a file is a great idea, as
> exemplified
>> > by
>> >> > the use of XML for the web.config and other configuration files

that
>> >> > ASP.Net
>> >> > and .Net in general uses.
>> >> >
>> >> > In fact, using the web.config file might be your best bet to
>> >> > begin
>> >> > with.
>> >> > You
>> >> > can easily use the built-in "appSetting s" element in the

web.config
> to
>> >> > define your own data, which can easily be read from the file at

run
>> > time.
>> >> > Example:
>> >> >
>> >> > <?xml version="1.0" encoding="utf-8" ?>
>> >> > <configuratio n>
>> >> > <appSettings>
>> >> > <add key="Connection String"
>> >> > value="server=b lah;uid=Blah;pw d=blahblah;data base=blah"/>
>> >> > <add key="VoyagerPat h" value="C:\Voyag erOnline" />
>> >> > <add key="Timeout" value="15" />
>> >> > </appSettings>
>> >> > ...
>> >> >
>> >> > These configuration elements are easy to fetch at run-time.

Example:
>> >> >
>> >> > Dim Timeout As int =
>> >> >
System.Configur ation.Configura tionSettings.Ap pSettings("Time out") >> >> >
>> >> > You can also define custom configuration sections, if you have

a lot
> of
>> >> > data
>> >> > and need to organize it into a nice tree hierarchy.
>> >> >
>> >> > --
>> >> > HTH,
>> >> > Kevin Spencer
>> >> > .Net Developer
>> >> > Microsoft MVP
>> >> > I get paid good money to
>> >> > solve puzzles for a living
>> >> >
>> >> > "Davíð Þórisson" <db**@hi.is> wrote in message
>> >> > news:eh******** *****@TK2MSFTNG P11.phx.gbl...
>> >> >> now in my web I have some global variables to be used in many
>> >> >> different
>> >> >> subpages, in the old ASP I simply loaded a variables.asp file

into
>> > memory
>> >> >> using the eval() function. Now I'd like to use XML but what

method
>> > would
>> >> >> I
>> >> >> use to load the entries from the xml file into memory and make

them
>> >> > quickly
>> >> >> accessible globally in the web code? Just need to know what
> functions
>> >> >> specifically I should start reading about!
>> >> >>
>> >> >> Thx
>> >> >>
>> >> >>
>> >> >
>> >> >
>> >>
>> >>
>> >
>> >
>>
>>
>
>



Nov 18 '05 #18

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

Similar topics

8
2536
by: jose luis fernandez diaz | last post by:
Hi, I am reading Stroustrup's book 'C++ Programming Language'. In the 10.4.9 section (Nonlocal Store) he says: "A variable defined outside any function (that is global, namespace, and class static variables) is initializated (constructed) before main is invoked . . ." .. . .
9
6902
by: Charley Kyd | last post by:
I'm a newbie who needs advice about how to use external files of JavaScript code. I spent an hour this afternoon browsing through JavaScript books at the local book store. In about 15 different titles, I found a total of about five pages that covered js files. For all practical purposes, these pages said, "You can use js files. But we won't tell you how." Therefore, I hope someone can answer a few questions about js files... 1....
4
1968
by: gsyoon | last post by:
hi, all. I'm trying to make a "framework" to store the return value of a function to a global memory. My first attempt was 1) void store_to_global( char * type_name ) { if ( strcmp( type_name, "CLASS_A") )
5
3495
by: j | last post by:
Anyone here feel that "global variables" is misleading for variables whose scope is file scope? "global" seems to imply global visibility, while this isn't true for variables whose scope is file scope. If you have a variable whose scope is file scope in another translation unit, you have to provide a local declaration to access that variable from the other translation unit. Also, I don't see "global variable" used once in the standard....
20
3504
by: Sushil | last post by:
Hi gurus I was reading FAQ "alloca cannot be written portably, and is difficult to implement on machines without a conventional stack." I understand that the standard does not mandate "heap" or "stack" I'm curious to know the implemenations which dont have stack or heap.
3
2005
by: Pavan | last post by:
Hi i would like to know abt the data variable storage in C like 1.where does global variables gets stored and why is it so .. 2.like wise static ,local variables, as for as i know i remember that localvariables/functionarguments gets stored in stack is it true then how abt this lets go with an explicit example since it can give me a exact answers
8
4872
by: Vishwanathan Raman | last post by:
Hi I have a declared a static DataSet object SOBJ in Global.asax.I also have a localy defined DataSet LSOBJ in Global.asax which I am storing in Application State.Is there any technical differences in the way both the objects are handled by IIS. Are both objects stored in different memory spaces? I can access both the objects in my web page. I will be grateful if some one can help me understand the difference.
3
1688
by: Daves | last post by:
Please take your time to read the following, it's simple although the text is 3 paragraphs... Everytime an user is logged in I need to make a call to my sql server database to grab some specific user settings and load into Session variables. So, I have a "Loggedin" event in login.aspx which does this. As users can be logged in (automatically) via HttpApplication & Cookies, I need to run this same code after that. I can put the same code...
3
14762
by: frothpoker | last post by:
Guys, I'm sure this has been asked a million times but I can't seem to formulate a google search that returns what i'm looking for. I've go a dev and live environment. Currently the DB connect string is hard coded into each php file which means i'm going to have to change every page - Arrgh!! If i put the DBonnect into a function and store it in an include file,
0
9515
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10207
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10154
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9993
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9029
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5558
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4109
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 we have to send another system
2
3713
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2913
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.