how to find the website root physical path

Discussion in 'ASP .Net' started by AAaron123, Mar 30, 2009.

  1. AAaron123

    AAaron123 Guest

    I've been playing around with physical paths.

    I need to know how to find the website root physical path.

    I tried various things and find I can get the path to my Projects folder, to
    the folder the current page is in various other things but I'm never sure
    any one thing will work in all cases.

    Suppose this is the site

    webSiteFolder
    Default.aspx
    subFolder1
    page1.aspx
    subFolder2
    page2.aspx

    Suppose the site is first entered by specifying /subFolder/page1.aspx rather
    than /Default.aspx as it usually done (maybe this is not relevant).

    Then, in a .vb file, no matter which page I'm in

    How do I find the directory path to Default.aspx?
    That is, to the web root folder.

    If I'm in page2 how would you specify page1.aspx?

    What is the difference between the Application folder and the web root
    folder?
    I think I know what the web root is but what is the Application root?


    Thanks in advance if you wade through the above and answer some of it!

    PS
    I find the web root now by searching upward until I find Default.aspx.
    Kludgy?
    AAaron123, Mar 30, 2009
    #1
    1. Advertising

  2. AAaron123

    Scott M. Guest

    There's no need to know the physical path, nor should you use it even if you
    knew it. You should ALWAYS be using relative paths within your site.

    You can always specify the root of the site by simply adding a forward-slash
    (/) to any relative reference.

    So, to get to your default page, you would simply need a path of
    "/default.aspx".

    If you were on page2 and needed a reference to page1, you'd do it relatively
    by indicating you need to go up one directory (to the parent folder of
    subfolder2) by using "../" and then indicating that you need to go into
    subfolder1 and finally page1: "../subfolder1/page1.aspx"

    The reason you don't want to use physcial paths is that they can change over
    time and between development and production servers. Relative paths should
    stay consistent.

    -Scott


    "AAaron123" <> wrote in message
    news:%23xI%...
    > I've been playing around with physical paths.
    >
    > I need to know how to find the website root physical path.
    >
    > I tried various things and find I can get the path to my Projects folder,
    > to the folder the current page is in various other things but I'm never
    > sure any one thing will work in all cases.
    >
    > Suppose this is the site
    >
    > webSiteFolder
    > Default.aspx
    > subFolder1
    > page1.aspx
    > subFolder2
    > page2.aspx
    >
    > Suppose the site is first entered by specifying /subFolder/page1.aspx
    > rather than /Default.aspx as it usually done (maybe this is not relevant).
    >
    > Then, in a .vb file, no matter which page I'm in
    >
    > How do I find the directory path to Default.aspx?
    > That is, to the web root folder.
    >
    > If I'm in page2 how would you specify page1.aspx?
    >
    > What is the difference between the Application folder and the web root
    > folder?
    > I think I know what the web root is but what is the Application root?
    >
    >
    > Thanks in advance if you wade through the above and answer some of it!
    >
    > PS
    > I find the web root now by searching upward until I find Default.aspx.
    > Kludgy?
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    Scott M., Mar 30, 2009
    #2
    1. Advertising

  3. AAaron123

    imransyed63

    Joined:
    May 16, 2006
    Messages:
    27
    Request.ApplicationPath will give you the root path of your website,
    as per your example,
    Request.ApplicationPath will return you webSiteFolder no matter on what page you are.
    imransyed63, Mar 30, 2009
    #3
  4. AAaron123

    psycho Guest

    You can use Server.MapPath() to get the physical path of current page
    being processed.
    psycho, Mar 30, 2009
    #4
  5. On Mar 30, 2:21 am, "AAaron123" <> wrote:
    > What is the difference between the Application folder and the web root
    > folder?
    >     I think I know what the web root is but what is the Application root?
    >


    Web (domain) root is a folder that corresponds to domain of the
    website created in IIS. Example: by default IIS has a sample website
    in the C:\Inetpub\wwwroot folder. This folder is a web root of http://localhost

    Application root is a folder that corresponds to URL of application.
    Typically, it the same as web domain root, but if you have http://localhost/app1,
    http://localhost/app2 then your application root is location of the
    path to ASP.NET application (e.g. c:\inetpub\wwwroot
    \VirtualDirectory1). The application root usually contains some
    specific files: web.config, bin-folder, etc.
    Alexey Smirnov, Mar 30, 2009
    #5
  6. AAaron123

    AAaron123 Guest

    I need to pass the physical path to SQLServer 2008 to create a database in a
    specified folder.

    It works OK if I use the long newFolder string I show below.

    But not if I add the newFolder = "/" statement.

    Can you figure a way to do that?



    Dim newFolder As String = "I:\My Documents\Visual Studio
    2008\WebSites\MySite\App_Data\"

    newFolder = "/"


    Thanks

    "Scott M." <> wrote in message
    news:...
    > There's no need to know the physical path, nor should you use it even if
    > you knew it. You should ALWAYS be using relative paths within your site.
    >
    > You can always specify the root of the site by simply adding a
    > forward-slash (/) to any relative reference.
    >
    > So, to get to your default page, you would simply need a path of
    > "/default.aspx".
    >
    > If you were on page2 and needed a reference to page1, you'd do it
    > relatively by indicating you need to go up one directory (to the parent
    > folder of subfolder2) by using "../" and then indicating that you need to
    > go into subfolder1 and finally page1: "../subfolder1/page1.aspx"
    >
    > The reason you don't want to use physcial paths is that they can change
    > over time and between development and production servers. Relative paths
    > should stay consistent.
    >
    > -Scott
    >
    >
    > "AAaron123" <> wrote in message
    > news:%23xI%...
    >> I've been playing around with physical paths.
    >>
    >> I need to know how to find the website root physical path.
    >>
    >> I tried various things and find I can get the path to my Projects folder,
    >> to the folder the current page is in various other things but I'm never
    >> sure any one thing will work in all cases.
    >>
    >> Suppose this is the site
    >>
    >> webSiteFolder
    >> Default.aspx
    >> subFolder1
    >> page1.aspx
    >> subFolder2
    >> page2.aspx
    >>
    >> Suppose the site is first entered by specifying /subFolder/page1.aspx
    >> rather than /Default.aspx as it usually done (maybe this is not
    >> relevant).
    >>
    >> Then, in a .vb file, no matter which page I'm in
    >>
    >> How do I find the directory path to Default.aspx?
    >> That is, to the web root folder.
    >>
    >> If I'm in page2 how would you specify page1.aspx?
    >>
    >> What is the difference between the Application folder and the web root
    >> folder?
    >> I think I know what the web root is but what is the Application root?
    >>
    >>
    >> Thanks in advance if you wade through the above and answer some of it!
    >>
    >> PS
    >> I find the web root now by searching upward until I find Default.aspx.
    >> Kludgy?
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >>

    >
    >
    AAaron123, Mar 30, 2009
    #6
  7. AAaron123

    AAaron123 Guest

    Please see my reply to Scott M.

    thanks

    "psycho" <> wrote in message
    news:...
    >
    > You can use Server.MapPath() to get the physical path of current page
    > being processed.
    >
    AAaron123, Mar 30, 2009
    #7
  8. AAaron123

    AAaron123 Guest

    Thanks for your extensive comments below.
    I'm not confident I really understand so I wrote some stuff below hoping
    you'll indicate agreement or disagreement.
    I know it's really too much to expect you to wade through but I can hope!

    If I open IIS on my machine and expand I see:
    My machine name(local computer)
    Web Sites
    Default Web Site
    many folder names including the what is my application root if I
    understand your note below (because it contains web.config, bin-folder,
    etc.)
    Properties show the path to be
    I:\My Documents\Visual Studio 2008\WebSites\MySite
    so this isthe application folder for my site


    I used IE to open http://localhost
    and got to
    http://localhost/localstart.asp
    I find that file in
    C:\Inetpub\wwwroot

    So is C:\Inetpub\wwwroot a web root folder
    Is there an Application frolder that goes with this?

    When I run my site I see
    http://localhost:1350/MySite/Default.aspx
    so is /MySite my web root folder

    In this case the web and root folder are the same.
    But they need not be?

    If they are not how can I get vb to give me the string
    I:\My Documents\Visual Studio 2008\WebSites\MySite\App_Data

    Thanks a lot



    "Alexey Smirnov" <> wrote in message
    news:...
    On Mar 30, 2:21 am, "AAaron123" <> wrote:
    > What is the difference between the Application folder and the web root
    > folder?
    > I think I know what the web root is but what is the Application root?
    >


    Web (domain) root is a folder that corresponds to domain of the
    website created in IIS. Example: by default IIS has a sample website
    in the C:\Inetpub\wwwroot folder. This folder is a web root of
    http://localhost

    Application root is a folder that corresponds to URL of application.
    Typically, it the same as web domain root, but if you have
    http://localhost/app1,
    http://localhost/app2 then your application root is location of the
    path to ASP.NET application (e.g. c:\inetpub\wwwroot
    \VirtualDirectory1). The application root usually contains some
    specific files: web.config, bin-folder, etc.
    AAaron123, Mar 30, 2009
    #8
  9. The easiest way to find the website root application's
    physical path is with Server.MapPath(Request.ApplicationPath).

    Server.MapPath(Request.ApplicationPath) gives you the string you need to pass the
    application's physical path to SQLServer 2008 to create a database in a specified folder.




    Juan T. Llibre, asp.net MVP
    asp.net faq : http://asp.net.do/faq/
    =========================
    "AAaron123" <> wrote in message news:...
    >I need to pass the physical path to SQLServer 2008 to create a database in a specified folder.
    >
    > It works OK if I use the long newFolder string I show below.
    >
    > But not if I add the newFolder = "/" statement.
    >
    > Can you figure a way to do that?
    >
    >
    >
    > Dim newFolder As String = "I:\My Documents\Visual Studio 2008\WebSites\MySite\App_Data\"
    >
    > newFolder = "/"
    >
    >
    > Thanks
    >
    > "Scott M." <> wrote in message news:...
    >> There's no need to know the physical path, nor should you use it even if you knew it. You should ALWAYS be using
    >> relative paths within your site.
    >>
    >> You can always specify the root of the site by simply adding a forward-slash (/) to any relative reference.
    >>
    >> So, to get to your default page, you would simply need a path of "/default.aspx".
    >>
    >> If you were on page2 and needed a reference to page1, you'd do it relatively by indicating you need to go up one
    >> directory (to the parent folder of subfolder2) by using "../" and then indicating that you need to go into subfolder1
    >> and finally page1: "../subfolder1/page1.aspx"
    >>
    >> The reason you don't want to use physcial paths is that they can change over time and between development and
    >> production servers. Relative paths should stay consistent.
    >>
    >> -Scott
    >>
    >>
    >> "AAaron123" <> wrote in message news:%23xI%...
    >>> I've been playing around with physical paths.
    >>>
    >>> I need to know how to find the website root physical path.
    >>>
    >>> I tried various things and find I can get the path to my Projects folder, to the folder the current page is in
    >>> various other things but I'm never sure any one thing will work in all cases.
    >>>
    >>> Suppose this is the site
    >>>
    >>> webSiteFolder
    >>> Default.aspx
    >>> subFolder1
    >>> page1.aspx
    >>> subFolder2
    >>> page2.aspx
    >>>
    >>> Suppose the site is first entered by specifying /subFolder/page1.aspx rather than /Default.aspx as it usually done
    >>> (maybe this is not relevant).
    >>>
    >>> Then, in a .vb file, no matter which page I'm in
    >>>
    >>> How do I find the directory path to Default.aspx?
    >>> That is, to the web root folder.
    >>>
    >>> If I'm in page2 how would you specify page1.aspx?
    >>>
    >>> What is the difference between the Application folder and the web root folder?
    >>> I think I know what the web root is but what is the Application root?
    >>>
    >>>
    >>> Thanks in advance if you wade through the above and answer some of it!
    >>>
    >>> PS
    >>> I find the web root now by searching upward until I find Default.aspx. Kludgy?
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>

    >>
    >>

    >
    >
    Juan T. Llibre, Mar 30, 2009
    #9
  10. On Mar 30, 3:33 pm, "AAaron123" <> wrote:
    > Thanks for your extensive comments below.
    > I'm not confident I really understand so I wrote some stuff below hoping
    > you'll indicate agreement or disagreement.
    > I know it's really too much to expect you to wade through but I can hope!
    >
    > If I open IIS on my machine and expand I see:
    > My machine name(local computer)
    >     Web Sites
    >         Default Web Site
    >             many folder names including the what is my application root if I
    > understand your note below (because it contains web.config, bin-folder,
    > etc.)
    > Properties show the path to be
    > I:\My Documents\Visual Studio 2008\WebSites\MySite
    > so this isthe application folder for my site
    >
    > I used IE to openhttp://localhost
    > and got tohttp://localhost/localstart.asp
    > I find that file in
    > C:\Inetpub\wwwroot
    >
    > So is C:\Inetpub\wwwroot a web root folder
    > Is there an Application frolder that goes with this?
    >
    > When I run my site I seehttp://localhost:1350/MySite/Default.aspx
    > so is /MySite my web root folder
    >
    > In this case the web and root folder are the same.
    > But they need not be?
    >
    > If they are not how can I get vb to give me the string
    > I:\My Documents\Visual Studio 2008\WebSites\MySite\App_Data
    >


    Aaron,

    In your example,

    C:\Inetpub\wwwroot is the web (domain) root folder pointed to http://localhost
    I:\My Documents\Visual Studio 2008\WebSites\MySite is the application
    root of http://localhost:1350/MySite/

    The port number of 1350 tells me that you are using ASP.NET
    development server from VS.NET, and this is maybe why you were
    confused by difference in localhost vs. localhost:1350. To make this
    more clear you just need to know following thing: a typical web
    application is a set of web pages (web forms), other files and
    directories, linked to each other. A website could have one or more
    web applications. Go to IIS, open a website properties, go to Home
    Directory tab. You will see an area with Application settings.
    Navigate to a any subdirectory in your website in IIS, again open
    Properties - Directory. You will see again Application settings. If
    settings are grayed out, subdirectory is a part of the parent
    application. Once you clicked Create you will mark that directory as a
    new web application.

    To get I:\My Documents\Visual Studio 2008\WebSites\MySite\App_Data use

    Server.MapPath("~/App_Data")
    Alexey Smirnov, Mar 30, 2009
    #10
  11. AAaron123

    AAaron123 Guest

    Thanks
    "Juan T. Llibre" <> wrote in message
    news:...
    > The easiest way to find the website root application's
    > physical path is with Server.MapPath(Request.ApplicationPath).
    >
    > Server.MapPath(Request.ApplicationPath) gives you the string you need to
    > pass the
    > application's physical path to SQLServer 2008 to create a database in a
    > specified folder.
    >
    >
    >
    >
    > Juan T. Llibre, asp.net MVP
    > asp.net faq : http://asp.net.do/faq/
    > =========================
    > "AAaron123" <> wrote in message
    > news:...
    >>I need to pass the physical path to SQLServer 2008 to create a database in
    >>a specified folder.
    >>
    >> It works OK if I use the long newFolder string I show below.
    >>
    >> But not if I add the newFolder = "/" statement.
    >>
    >> Can you figure a way to do that?
    >>
    >>
    >>
    >> Dim newFolder As String = "I:\My Documents\Visual Studio
    >> 2008\WebSites\MySite\App_Data\"
    >>
    >> newFolder = "/"
    >>
    >>
    >> Thanks
    >>
    >> "Scott M." <> wrote in message
    >> news:...
    >>> There's no need to know the physical path, nor should you use it even if
    >>> you knew it. You should ALWAYS be using relative paths within your
    >>> site.
    >>>
    >>> You can always specify the root of the site by simply adding a
    >>> forward-slash (/) to any relative reference.
    >>>
    >>> So, to get to your default page, you would simply need a path of
    >>> "/default.aspx".
    >>>
    >>> If you were on page2 and needed a reference to page1, you'd do it
    >>> relatively by indicating you need to go up one directory (to the parent
    >>> folder of subfolder2) by using "../" and then indicating that you need
    >>> to go into subfolder1 and finally page1: "../subfolder1/page1.aspx"
    >>>
    >>> The reason you don't want to use physcial paths is that they can change
    >>> over time and between development and production servers. Relative
    >>> paths should stay consistent.
    >>>
    >>> -Scott
    >>>
    >>>
    >>> "AAaron123" <> wrote in message
    >>> news:%23xI%...
    >>>> I've been playing around with physical paths.
    >>>>
    >>>> I need to know how to find the website root physical path.
    >>>>
    >>>> I tried various things and find I can get the path to my Projects
    >>>> folder, to the folder the current page is in various other things but
    >>>> I'm never sure any one thing will work in all cases.
    >>>>
    >>>> Suppose this is the site
    >>>>
    >>>> webSiteFolder
    >>>> Default.aspx
    >>>> subFolder1
    >>>> page1.aspx
    >>>> subFolder2
    >>>> page2.aspx
    >>>>
    >>>> Suppose the site is first entered by specifying /subFolder/page1.aspx
    >>>> rather than /Default.aspx as it usually done (maybe this is not
    >>>> relevant).
    >>>>
    >>>> Then, in a .vb file, no matter which page I'm in
    >>>>
    >>>> How do I find the directory path to Default.aspx?
    >>>> That is, to the web root folder.
    >>>>
    >>>> If I'm in page2 how would you specify page1.aspx?
    >>>>
    >>>> What is the difference between the Application folder and the web root
    >>>> folder?
    >>>> I think I know what the web root is but what is the Application
    >>>> root?
    >>>>
    >>>>
    >>>> Thanks in advance if you wade through the above and answer some of it!
    >>>>
    >>>> PS
    >>>> I find the web root now by searching upward until I find Default.aspx.
    >>>> Kludgy?
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
    >
    AAaron123, Mar 30, 2009
    #11
  12. AAaron123

    AAaron123 Guest

    That great!

    Thanks a lot.

    "Alexey Smirnov" <> wrote in message
    news:...
    On Mar 30, 3:33 pm, "AAaron123" <> wrote:
    > Thanks for your extensive comments below.
    > I'm not confident I really understand so I wrote some stuff below hoping
    > you'll indicate agreement or disagreement.
    > I know it's really too much to expect you to wade through but I can hope!
    >
    > If I open IIS on my machine and expand I see:
    > My machine name(local computer)
    > Web Sites
    > Default Web Site
    > many folder names including the what is my application root if I
    > understand your note below (because it contains web.config, bin-folder,
    > etc.)
    > Properties show the path to be
    > I:\My Documents\Visual Studio 2008\WebSites\MySite
    > so this isthe application folder for my site
    >
    > I used IE to openhttp://localhost
    > and got tohttp://localhost/localstart.asp
    > I find that file in
    > C:\Inetpub\wwwroot
    >
    > So is C:\Inetpub\wwwroot a web root folder
    > Is there an Application frolder that goes with this?
    >
    > When I run my site I seehttp://localhost:1350/MySite/Default.aspx
    > so is /MySite my web root folder
    >
    > In this case the web and root folder are the same.
    > But they need not be?
    >
    > If they are not how can I get vb to give me the string
    > I:\My Documents\Visual Studio 2008\WebSites\MySite\App_Data
    >


    Aaron,

    In your example,

    C:\Inetpub\wwwroot is the web (domain) root folder pointed to
    http://localhost
    I:\My Documents\Visual Studio 2008\WebSites\MySite is the application
    root of http://localhost:1350/MySite/

    The port number of 1350 tells me that you are using ASP.NET
    development server from VS.NET, and this is maybe why you were
    confused by difference in localhost vs. localhost:1350. To make this
    more clear you just need to know following thing: a typical web
    application is a set of web pages (web forms), other files and
    directories, linked to each other. A website could have one or more
    web applications. Go to IIS, open a website properties, go to Home
    Directory tab. You will see an area with Application settings.
    Navigate to a any subdirectory in your website in IIS, again open
    Properties - Directory. You will see again Application settings. If
    settings are grayed out, subdirectory is a part of the parent
    application. Once you clicked Create you will mark that directory as a
    new web application.

    To get I:\My Documents\Visual Studio 2008\WebSites\MySite\App_Data use

    Server.MapPath("~/App_Data")
    AAaron123, Mar 30, 2009
    #12
    1. Advertising

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. =?Utf-8?B?SmVmZiBCZWVt?=

    physical path to virtual path under virtual directory

    =?Utf-8?B?SmVmZiBCZWVt?=, Aug 1, 2007, in forum: ASP .Net
    Replies:
    4
    Views:
    1,035
    Eliyahu Goldin
    Aug 1, 2007
  2. marss
    Replies:
    5
    Views:
    1,001
    marss
    Sep 13, 2007
  3. Scott Tilton

    Convert Physical path to Virtual path?

    Scott Tilton, Jul 11, 2003, in forum: ASP General
    Replies:
    2
    Views:
    608
    Dhananjay Modak
    Jul 11, 2003
  4. Guest

    Virtual Path and physical root

    Guest, Aug 2, 2004, in forum: ASP General
    Replies:
    4
    Views:
    216
    Guest
    Aug 2, 2004
  5. Shawn McNiven

    how to find website root path

    Shawn McNiven, Mar 13, 2005, in forum: Javascript
    Replies:
    1
    Views:
    149
    Evertjan.
    Mar 13, 2005
Loading...

Share This Page