SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict darkwater23's Avatar
    Join Date
    Nov 2005
    Location
    Omaha, NE
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Referencing Web.config app setting in controls

    Hello!

    I have a noob questions for you all.

    I added this to my Web.config file:

    <add key="xmlData" value="<path_to_file>formdata.xml"/>

    I can extract this value just fine in my methods, but I'd like to put it into an XML control like this:

    <asp:XmlDataSource ID="xdsFormData" runat="server" DataFile="ConfigurationSettings.AppSettings["xmlData"]"></asp:XmlDataSource>

    But, naturally, that doesn't work. I tried doing the " + ConfigurationSettings.AppSettings["xmlData"] + " thing, but that didn't work.

    What is the proper syntax for getting my app setting into controls?

    Thanks!
    Last edited by darkwater23; Aug 2, 2007 at 12:47. Reason: typo

  2. #2
    SitePoint Guru Wullie's Avatar
    Join Date
    Oct 2002
    Location
    Greenock, Scotland
    Posts
    701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Set the DataFile property in the Init event of the XMLDataSource control.

    Protected Sub xdsFormData_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles xdsFormData.Init
    xdsFormData.DataFile = ConfigurationManager.AppSettings("xmlData")
    End Sub
    ASP.NET Freelance Web Developer
    Bored? Check out my photography folio at Flickr

  3. #3
    SitePoint Wizard
    Join Date
    Feb 2007
    Posts
    1,274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use the <%$ AppSettings: xmlData %> expression. No need to code anything:

    Code:
    asp:XmlDataSource ID="xdsFormData" runat="server" DataFile="<%$AppSettings:xmlData%>" />

  4. #4
    SitePoint Guru Wullie's Avatar
    Join Date
    Oct 2002
    Location
    Greenock, Scotland
    Posts
    701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by honeymonster View Post
    Use the <&#37;$ AppSettings: xmlData %> expression. No need to code anything:
    Ahhhhhh, I forgot about that technique honeymonster....nice one!
    ASP.NET Freelance Web Developer
    Bored? Check out my photography folio at Flickr

  5. #5
    SitePoint Addict darkwater23's Avatar
    Join Date
    Nov 2005
    Location
    Omaha, NE
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perfect! Thanks alot guys!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •