dll read config file

Discussion in 'Microsoft ASP .NET' started by NuB, Sep 29, 2005.

  1. NuB

    NuB Guest

    I'm creating a C# class file(DLL) that will be used by an asp.net
    application. In the DLL I want to read a web.config, or app.config file so
    some information can change without having to go into the code itself. How
    can I have the dll read a app.config or web.config file for data?

    The information I'm looking to store in the file is servernames, file
    locations, etc.


    thanks
     
    NuB, Sep 29, 2005
    #1
    1. Advertisements

  2. NuB

    Brock Allen Guest

    Check out <appSetings> and the System.Configuration.ConfigurationSettings
    class for v1.x. Other than that, there's no good way to read the config file
    (other than manual XML parsing). In v2.0 there's a proper API for reading
    the settings via System.Configuration.ConfigurationManager.

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen

    > I'm creating a C# class file(DLL) that will be used by an asp.net
    > application. In the DLL I want to read a web.config, or app.config
    > file so some information can change without having to go into the code
    > itself. How can I have the dll read a app.config or web.config file
    > for data?
    >
    > The information I'm looking to store in the file is servernames, file
    > locations, etc.
    >
    > thanks
    >
     
    Brock Allen, Sep 29, 2005
    #2
    1. Advertisements

  3. NuB

    NuB Guest

    I know appSettings will work from a asp.net app but what about a dll that is
    not included in the asp.net project?




    "Brock Allen" <> wrote in message
    news:...
    > Check out <appSetings> and the System.Configuration.ConfigurationSettings
    > class for v1.x. Other than that, there's no good way to read the config
    > file (other than manual XML parsing). In v2.0 there's a proper API for
    > reading the settings via System.Configuration.ConfigurationManager.
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen
    >
    >> I'm creating a C# class file(DLL) that will be used by an asp.net
    >> application. In the DLL I want to read a web.config, or app.config
    >> file so some information can change without having to go into the code
    >> itself. How can I have the dll read a app.config or web.config file
    >> for data?
    >>
    >> The information I'm looking to store in the file is servernames, file
    >> locations, etc.
    >>
    >> thanks
    >>

    >
    >
     
    NuB, Sep 29, 2005
    #3
  4. NuB

    Lucas Tam Guest

    "NuB" <> wrote in
    news::

    > I'm creating a C# class file(DLL) that will be used by an asp.net
    > application. In the DLL I want to read a web.config, or app.config
    > file so some information can change without having to go into the code
    > itself. How can I have the dll read a app.config or web.config file
    > for data?


    Use the standard methods for accessing the configuration file:

    System.Configuration.ConfigurationSettings.AppSettings.Item("MyKey")

    When you instantiate your DLL in a ASP.NET project, it will have access the
    the web.config.

    When you instantiate your DLL in a VB.NET project, it will have access the
    the app.config.

    --
    Lucas Tam ()
    Please delete "REMOVE" from the e-mail address when replying.

    Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com
     
    Lucas Tam, Sep 29, 2005
    #4
  5. NuB

    NuB Guest

    i want a seperate config file for the dll, in case the dll is going to used
    by another type of project such as a windows app. Right now its being
    designed for a asp.net web app, but that could change in the future.

    Could I create an XML file and read the tags in that for my information, and
    if so how would i do that?



    "Lucas Tam" <> wrote in message
    news:Xns96E085B4C171Fnntprogerscom@127.0.0.1...
    > "NuB" <> wrote in
    > news::
    >
    >> I'm creating a C# class file(DLL) that will be used by an asp.net
    >> application. In the DLL I want to read a web.config, or app.config
    >> file so some information can change without having to go into the code
    >> itself. How can I have the dll read a app.config or web.config file
    >> for data?

    >
    > Use the standard methods for accessing the configuration file:
    >
    > System.Configuration.ConfigurationSettings.AppSettings.Item("MyKey")
    >
    > When you instantiate your DLL in a ASP.NET project, it will have access
    > the
    > the web.config.
    >
    > When you instantiate your DLL in a VB.NET project, it will have access the
    > the app.config.
    >
    > --
    > Lucas Tam ()
    > Please delete "REMOVE" from the e-mail address when replying.
    >
    > Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com
     
    NuB, Sep 29, 2005
    #5
  6. NuB

    Lucas Tam Guest

    "NuB" <> wrote in
    news::

    > i want a seperate config file for the dll, in case the dll is going to
    > used by another type of project such as a windows app. Right now its
    > being designed for a asp.net web app, but that could change in the
    > future.
    >
    > Could I create an XML file and read the tags in that for my
    > information, and if so how would i do that?


    No need to create a separate config file - the way you read the config file
    is the same for both ASP.NET and VB.NET projects. The DLL will work in both
    ASP.NET and VB.NET projects (as long as you use the System.Configuration
    classes.

    The DLL will switch "files" depending on the context it is loaded (i.e.
    ASP.NET or VB.NET).

    --
    Lucas Tam ()
    Please delete "REMOVE" from the e-mail address when replying.

    Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com
     
    Lucas Tam, Sep 29, 2005
    #6
  7. NuB

    NuB Guest

    So in my web.config file for the asp.net web app I'm creating, if I have a
    key named server and the actual asp.net file does not use that key I can
    read it from the DLL I'm creating?




    "Lucas Tam" <> wrote in message
    news:Xns96E08E49D4692nntprogerscom@127.0.0.1...
    > "NuB" <> wrote in
    > news::
    >
    >> i want a seperate config file for the dll, in case the dll is going to
    >> used by another type of project such as a windows app. Right now its
    >> being designed for a asp.net web app, but that could change in the
    >> future.
    >>
    >> Could I create an XML file and read the tags in that for my
    >> information, and if so how would i do that?

    >
    > No need to create a separate config file - the way you read the config
    > file
    > is the same for both ASP.NET and VB.NET projects. The DLL will work in
    > both
    > ASP.NET and VB.NET projects (as long as you use the System.Configuration
    > classes.
    >
    > The DLL will switch "files" depending on the context it is loaded (i.e.
    > ASP.NET or VB.NET).
    >
    > --
    > Lucas Tam ()
    > Please delete "REMOVE" from the e-mail address when replying.
    >
    > Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com
     
    NuB, Sep 29, 2005
    #7
  8. NuB

    NuB Guest

    also to note: this is a separate project DLL (class). I did not add a class
    to an existing asp.net web application. I created a seperate project which
    is just this DLL file I want to use
    "Lucas Tam" <> wrote in message
    news:Xns96E08E49D4692nntprogerscom@127.0.0.1...
    > "NuB" <> wrote in
    > news::
    >
    >> i want a seperate config file for the dll, in case the dll is going to
    >> used by another type of project such as a windows app. Right now its
    >> being designed for a asp.net web app, but that could change in the
    >> future.
    >>
    >> Could I create an XML file and read the tags in that for my
    >> information, and if so how would i do that?

    >
    > No need to create a separate config file - the way you read the config
    > file
    > is the same for both ASP.NET and VB.NET projects. The DLL will work in
    > both
    > ASP.NET and VB.NET projects (as long as you use the System.Configuration
    > classes.
    >
    > The DLL will switch "files" depending on the context it is loaded (i.e.
    > ASP.NET or VB.NET).
    >
    > --
    > Lucas Tam ()
    > Please delete "REMOVE" from the e-mail address when replying.
    >
    > Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com
     
    NuB, Sep 29, 2005
    #8
  9. NuB

    Lucas Tam Guest

    "NuB" <> wrote in
    news:#:

    > So in my web.config file for the asp.net web app I'm creating, if I
    > have a key named server and the actual asp.net file does not use that
    > key I can read it from the DLL I'm creating?



    I believe your DLL will read keys from the web.config.

    Not sure if you can have a DLL config AND a Web.config.



    --
    Lucas Tam ()
    Please delete "REMOVE" from the e-mail address when replying.

    Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com
     
    Lucas Tam, Sep 29, 2005
    #9
  10. NuB

    Brock Allen Guest

    An assembly can access the application's config file. What do you mean by
    "not included in the asp.net project"?

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen

    > I know appSettings will work from a asp.net app but what about a dll
    > that is not included in the asp.net project?
    >
    > "Brock Allen" <> wrote in message
    > news:...
    >
    >> Check out <appSetings> and the
    >> System.Configuration.ConfigurationSettings class for v1.x. Other than
    >> that, there's no good way to read the config file (other than manual
    >> XML parsing). In v2.0 there's a proper API for reading the settings
    >> via System.Configuration.ConfigurationManager.
    >>
    >> -Brock
    >> DevelopMentor
    >> http://staff.develop.com/ballen
    >>> I'm creating a C# class file(DLL) that will be used by an asp.net
    >>> application. In the DLL I want to read a web.config, or app.config
    >>> file so some information can change without having to go into the
    >>> code itself. How can I have the dll read a app.config or web.config
    >>> file for data?
    >>>
    >>> The information I'm looking to store in the file is servernames,
    >>> file locations, etc.
    >>>
    >>> thanks
    >>>
     
    Brock Allen, Sep 29, 2005
    #10
  11. NuB

    NuB Guest

    its a seperate project. I created a new project which is the dll I'm
    creating. This dll can be used by either an asp.net project or a windows
    application.

    I didn't add a Class to an existing asp.net project, it is own project


    "Brock Allen" <> wrote in message
    news:...
    > An assembly can access the application's config file. What do you mean by
    > "not included in the asp.net project"?
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen
    >
    >> I know appSettings will work from a asp.net app but what about a dll
    >> that is not included in the asp.net project?
    >>
    >> "Brock Allen" <> wrote in message
    >> news:...
    >>
    >>> Check out <appSetings> and the
    >>> System.Configuration.ConfigurationSettings class for v1.x. Other than
    >>> that, there's no good way to read the config file (other than manual
    >>> XML parsing). In v2.0 there's a proper API for reading the settings
    >>> via System.Configuration.ConfigurationManager.
    >>>
    >>> -Brock
    >>> DevelopMentor
    >>> http://staff.develop.com/ballen
    >>>> I'm creating a C# class file(DLL) that will be used by an asp.net
    >>>> application. In the DLL I want to read a web.config, or app.config
    >>>> file so some information can change without having to go into the
    >>>> code itself. How can I have the dll read a app.config or web.config
    >>>> file for data?
    >>>>
    >>>> The information I'm looking to store in the file is servernames,
    >>>> file locations, etc.
    >>>>
    >>>> thanks
    >>>>

    >
    >
     
    NuB, Sep 30, 2005
    #11
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bob
    Replies:
    7
    Views:
    236
    Saravana [MVP]
    May 5, 2004
  2. Hardy Wang

    Read config setting from web.config performance?

    Hardy Wang, Jul 29, 2004, in forum: Microsoft ASP .NET
    Replies:
    2
    Views:
    210
    Joe Fallon
    Jul 31, 2004
  3. CSharpner
    Replies:
    0
    Views:
    767
    CSharpner
    Apr 9, 2007
  4. M Irfan

    Reading config file other than web.config

    M Irfan, Apr 17, 2007, in forum: Microsoft ASP .NET
    Replies:
    2
    Views:
    1,347
    M Irfan
    Apr 18, 2007
  5. Ollie Riches

    encrypting config file that aren't web config files...

    Ollie Riches, Dec 4, 2008, in forum: Microsoft ASP .NET
    Replies:
    1
    Views:
    448
    Gregory A. Beamer
    Dec 4, 2008
Loading...

Share This Page