Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. How can I programmatically retrieve the app_data path

How can I programmatically retrieve the app_data path

Scheduled Pinned Locked Moved ASP.NET
databasequestionregexxmljson
5 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MBursill
    wrote on last edited by
    #1

    I have an XML file in my app_data directory. My Data Access layer (a class library project) needs to know where the XML file is. I currently have:

    c:\projects\My website\ (solution file is here)
    c:\projects\My website\website (aspx files, web config, & junk)
    c:\projects\My website\website\app_data\ (a few database files and an xml file)
    c:\projects\My website\websiteDA\ (project folder for data access class library)

    If I add the DA class library project as a reference to my website project, is there any way for the class library to know what the data directory of the website may be. Using something like: XmlTextReader settingsReader = new XmlTextReader("settings.xml"); tells me it's looking in: C:\projects\My website\ the same folder as the solution file. Very odd. I would have expected c:\projects\My website\website DB access gets around this by somehow parsing "|DataDirectory|" in the connection string, resolving it to match the app_data path. Could I do something similar? -Mike.

    N 1 Reply Last reply
    0
    • M MBursill

      I have an XML file in my app_data directory. My Data Access layer (a class library project) needs to know where the XML file is. I currently have:

      c:\projects\My website\ (solution file is here)
      c:\projects\My website\website (aspx files, web config, & junk)
      c:\projects\My website\website\app_data\ (a few database files and an xml file)
      c:\projects\My website\websiteDA\ (project folder for data access class library)

      If I add the DA class library project as a reference to my website project, is there any way for the class library to know what the data directory of the website may be. Using something like: XmlTextReader settingsReader = new XmlTextReader("settings.xml"); tells me it's looking in: C:\projects\My website\ the same folder as the solution file. Very odd. I would have expected c:\projects\My website\website DB access gets around this by somehow parsing "|DataDirectory|" in the connection string, resolving it to match the app_data path. Could I do something similar? -Mike.

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      Server.MapPath("settings.xml") http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/html/270433db-6a1a-42b1-86fa-9c4ca07b75e1.asp[^]


      only two letters away from being an asset

      M 1 Reply Last reply
      0
      • N Not Active

        Server.MapPath("settings.xml") http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/html/270433db-6a1a-42b1-86fa-9c4ca07b75e1.asp[^]


        only two letters away from being an asset

        M Offline
        M Offline
        MBursill
        wrote on last edited by
        #3

        That works if I'm trying to resolve a path from a page in the web project. However, I'm trying to accomplish the same from inside a class library referenced by the web project. -Mike.

        N M 2 Replies Last reply
        0
        • M MBursill

          That works if I'm trying to resolve a path from a page in the web project. However, I'm trying to accomplish the same from inside a class library referenced by the web project. -Mike.

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          The class library code is running in appdomain of the web application so you have access to the HttpContext.Current.Server.


          only two letters away from being an asset

          1 Reply Last reply
          0
          • M MBursill

            That works if I'm trying to resolve a path from a page in the web project. However, I'm trying to accomplish the same from inside a class library referenced by the web project. -Mike.

            M Offline
            M Offline
            MBursill
            wrote on last edited by
            #5

            I managed to solve my own problem, and here it is:

            string strDataDirectory = AppDomain.CurrentDomain.GetData("DataDirectory").ToString();

            http://blogs.msdn.com/smartclientdata/archive/2005/08/26/456886.aspx -Mike.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups