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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • zjut

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

    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
    ---------------------------------------------------------------------------------------
    <configuratio n>

    <appSettings>
    <add key="LocalizedC ountryFileDirec tory" value="D:\Locat ion" />
    </appSettings>
    </configuration
    ---------------------------------------------------------------------------------------

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

    String filePath =
    ConfigurationSe ttings.AppSetti ngs["LocalizedCount ryFileDirectory "];

    =============== =============== =============== ==
    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 !
  • Mike Hanson

    #2
    RE: How to read info from xml in asp.net component ?

    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

    "zjut" wrote:
    [color=blue]
    > 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 :
    > ---------------------------------------------------------------------------------------
    > <configuratio n>
    >
    > <appSettings>
    > <add key="LocalizedC ountryFileDirec tory" value="D:\Locat ion" />
    > </appSettings>
    > </configuration>
    > ---------------------------------------------------------------------------------------
    >
    > and i read it in this way:
    > =============== =============== ==============
    >
    > String filePath =
    > ConfigurationSe ttings.AppSetti ngs["LocalizedCount ryFileDirectory "];
    >
    > =============== =============== =============== ==
    > 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 ![/color]

    Comment

    Working...