Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > how to find the website root physical path

Reply
Thread Tools

how to find the website root physical path

 
 
AAaron123
Guest
Posts: n/a
 
      03-30-2009
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?












 
Reply With Quote
 
 
 
 
Scott M.
Guest
Posts: n/a
 
      03-30-2009
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" <(E-Mail Removed)> wrote in message
news:%23xI%(E-Mail Removed)...
> 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?
>
>
>
>
>
>
>
>
>
>
>
>



 
Reply With Quote
 
 
 
 
imransyed63 imransyed63 is offline
Member
Join Date: May 2006
Posts: 31
 
      03-30-2009
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.
 
Reply With Quote
 
psycho
Guest
Posts: n/a
 
      03-30-2009

You can use Server.MapPath() to get the physical path of current page
being processed.

 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      03-30-2009
On Mar 30, 2:21*am, "AAaron123" <(E-Mail Removed)> 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.

 
Reply With Quote
 
AAaron123
Guest
Posts: n/a
 
      03-30-2009
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." <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:%23xI%(E-Mail Removed)...
>> 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?
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>

>
>



 
Reply With Quote
 
AAaron123
Guest
Posts: n/a
 
      03-30-2009
Please see my reply to Scott M.

thanks

"psycho" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> You can use Server.MapPath() to get the physical path of current page
> being processed.
>



 
Reply With Quote
 
AAaron123
Guest
Posts: n/a
 
      03-30-2009
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
On Mar 30, 2:21 am, "AAaron123" <(E-Mail Removed)> 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.


 
Reply With Quote
 
Juan T. Llibre
Guest
Posts: n/a
 
      03-30-2009
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" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
>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." <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
>> 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" <(E-Mail Removed)> wrote in message news:%23xI%(E-Mail Removed)...
>>> 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?
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>

>>
>>

>
>




 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      03-30-2009
On Mar 30, 3:33*pm, "AAaron123" <(E-Mail Removed)> 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")
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How get the virtual path based on the physical path? marss ASP .Net 5 09-13-2007 04:20 PM
physical path to virtual path under virtual directory =?Utf-8?B?SmVmZiBCZWVt?= ASP .Net 4 08-01-2007 02:59 PM
how to find website root path Shawn McNiven Javascript 1 03-13-2005 10:03 AM
Virtual Path and physical root ASP General 4 08-02-2004 08:31 PM



Advertisments