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
  1. Home
  2. General Programming
  3. C#
  4. How to get the physical path of a virtual directory?

How to get the physical path of a virtual directory?

Scheduled Pinned Locked Moved C#
questioncsharptutorial
5 Posts 3 Posters 0 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.
  • P Offline
    P Offline
    PravinSingh
    wrote on last edited by
    #1

    I have a desktop application where user can enter a virtual directory path (like http://localhost/MySite, or http://MyMachine/MySite). The path will always be local (both virtual and physical directories located on that machine itself). I should then open "MySite" in a browser, but before that I need to fetch some settings from its web.config file. For that I should know the physical location of web.config file (which is the root of "MySite") so that I can open it. So the question is: how do I get the physical location of "MySite"? Or is there any other approach to what I want to achieve? Please remember, I have a Winform application which has nothing to do with the site "MySite", it just gets its URL through an editbox. I am new to .Net, so please forgive any stupidity.


    It's better to know some of the questions than all of the answers.
    Pravin.

    L M 2 Replies Last reply
    0
    • P PravinSingh

      I have a desktop application where user can enter a virtual directory path (like http://localhost/MySite, or http://MyMachine/MySite). The path will always be local (both virtual and physical directories located on that machine itself). I should then open "MySite" in a browser, but before that I need to fetch some settings from its web.config file. For that I should know the physical location of web.config file (which is the root of "MySite") so that I can open it. So the question is: how do I get the physical location of "MySite"? Or is there any other approach to what I want to achieve? Please remember, I have a Winform application which has nothing to do with the site "MySite", it just gets its URL through an editbox. I am new to .Net, so please forgive any stupidity.


      It's better to know some of the questions than all of the answers.
      Pravin.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      I don't think you can, and this is why: your local web server somehow knows where the root of the local web is, it is like an application setting to it. Example: I am using XAMPP (=Apache) to serve a local PHP-based web site, it holds its root location deep inside a configuration file called "httpd.conf"; I am also using another web server serving an ASP.NET-based web site, it uses a different web root, stored in a different way. How could an application external to all these web servers know where to look for your web root(s)? Maybe this would work for you: organize an application setting "webroot" for your WinForm, initially "webroot" is empty. Have your app obtain its "webroot" from its setting, when getting a value, just use it; when getting no value, ask the user to locate the web root, and update the setting. That is harassing the user only once (and causing a major problem when you decide to move the web root, unless you also provide a button "Update Web Root Location" which basically empties "webroot". :)

      Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

      P 1 Reply Last reply
      0
      • L Luc Pattyn

        I don't think you can, and this is why: your local web server somehow knows where the root of the local web is, it is like an application setting to it. Example: I am using XAMPP (=Apache) to serve a local PHP-based web site, it holds its root location deep inside a configuration file called "httpd.conf"; I am also using another web server serving an ASP.NET-based web site, it uses a different web root, stored in a different way. How could an application external to all these web servers know where to look for your web root(s)? Maybe this would work for you: organize an application setting "webroot" for your WinForm, initially "webroot" is empty. Have your app obtain its "webroot" from its setting, when getting a value, just use it; when getting no value, ask the user to locate the web root, and update the setting. That is harassing the user only once (and causing a major problem when you decide to move the web root, unless you also provide a button "Update Web Root Location" which basically empties "webroot". :)

        Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

        P Offline
        P Offline
        PravinSingh
        wrote on last edited by
        #3

        Thanks for the answer, Luc. I already have this option of asking the user for webroot, storing them and later showing them in a drop-down to let him choose (or type a new one). I just wanted to remove this harassment by making my app a little more intelligent. All my users will be on Windows, using IIS 7, if that gives you any more ideas.


        It's better to know some of the questions than all of the answers.
        Pravin.

        L 1 Reply Last reply
        0
        • P PravinSingh

          Thanks for the answer, Luc. I already have this option of asking the user for webroot, storing them and later showing them in a drop-down to let him choose (or type a new one). I just wanted to remove this harassment by making my app a little more intelligent. All my users will be on Windows, using IIS 7, if that gives you any more ideas.


          It's better to know some of the questions than all of the answers.
          Pravin.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          PravinSingh wrote:

          any more ideas

          No, not really. A web server should obviously know, but also not reveal, where the web root is. As I explained, you don't need to ask the user each time, once is enough (unless it changes). And that once could probably be at installation time of your app. :)

          Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

          1 Reply Last reply
          0
          • P PravinSingh

            I have a desktop application where user can enter a virtual directory path (like http://localhost/MySite, or http://MyMachine/MySite). The path will always be local (both virtual and physical directories located on that machine itself). I should then open "MySite" in a browser, but before that I need to fetch some settings from its web.config file. For that I should know the physical location of web.config file (which is the root of "MySite") so that I can open it. So the question is: how do I get the physical location of "MySite"? Or is there any other approach to what I want to achieve? Please remember, I have a Winform application which has nothing to do with the site "MySite", it just gets its URL through an editbox. I am new to .Net, so please forgive any stupidity.


            It's better to know some of the questions than all of the answers.
            Pravin.

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            Since your site will always run on IIS, you can make the site an ASP.NET app and add a web service to the site that the calling app can call to ask for the information. That's what you should be doing anyway....client apps shouldn't need direct access to that stuff.

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            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