How to read info from xml in asp.net component ?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am writing a component like dropdownlist whose content should be read from
xml,and i put the path of the xml file into the web.config fallow as
---------------------------------------------------------------------------------------
<configuration>

<appSettings>
<add key="LocalizedCountryFileDirectory" value="D:\Location" />
</appSettings>
</configuration
---------------------------------------------------------------------------------------

and i read it in this way:
============================================

String filePath =
ConfigurationSettings.AppSettings["LocalizedCountryFileDirectory"];

===============================================
But it sames not to work, can u give me some suggestion to make it work , or
give me some other way to the the path. your answer will be appreciated.
thanx !
 
I don't see anything wrong with your code to read the file path in, I use the
same mechanism frequently and it works fine.

The only thing I can see from your code that might cause a problem is that
it has a single backslash "\" character. Depending on how you attempt to use
the string you have read in, you may get an exception as the CLR will
interpret the backslash as an escape and apply it to the following character.
So it will be trying to apply some special meaning to \L which will may
cause an exception, but at least give you unexpected behaviour.

What do you do with the string once you have read it in from the config file?

Regards
Mike Hanson
 
Back
Top