In the following table the page executing the code is at the following physical location on my machine:
C:\Users\me\Documents\Visual Studio 2010\Projects\TestStuff\TestStuff\Nested\Paths.aspx
Property/Method and Description | Result |
Request.ApplicationPath
Gets the root virtual path.
|
/TestStuff |
Request.CurrentExecutionFilePath
Gets the virtual path to the current file. Same as Request.Path and Request.FilePath.
|
/TestStuff/Nested/Paths.aspx |
Request.CurrentExecutionFilePathExtension
Gets the file extension of the current file.
|
.aspx |
Request.FilePath
Gets the virtual path to the current file. Same as Request.CurrentExecutionFilePath and Request.Path.
|
/TestStuff/Nested/Paths.aspx |
Request.MapPath("")
Gets the full physical path to the current directory. Seems to be the same as Server.MapPath("").
|
C:\Users\me\Documents\Visual Studio 2010\Projects\TestStuff\TestStuff\Nested |
Request.Path
Gets the virtual path to the current file. Same as Request.CurrentExecutionFilePath and Request.FilePath.
|
/TestStuff/Nested/Paths.aspx |
Request.PhysicalApplicationPath
Gets the physical path to the root directory. Seems to be the same as AppDomain.CurrentDomain.BaseDirectory.
|
C:\Users\me\Documents\Visual Studio 2010\Projects\TestStuff\TestStuff\ |
Request.PhysicalPath
Gets the full physical path to the current file.
|
C:\Users\me\Documents\Visual Studio 2010\Projects\TestStuff\TestStuff\Nested\Paths.aspx |
AppDomain.CurrentDomain.BaseDirectory
Gets the physical path to the root directory. Seems to be the same as Request.PhysicalApplicationPath.
|
C:\Users\me\Documents\Visual Studio 2010\Projects\TestStuff\TestStuff\ |
Server.MapPath("")
Gets the full physical path to the current directory. Seems to be the same as Request.MapPath("").
|
C:\Users\me\Documents\Visual Studio 2010\Projects\TestStuff\TestStuff\Nested |
Also, if you are joining a directory to a file/path I recommend using the Path.Combine method found in the System.IO namespace. Here is an example:
using System.IO;
string fileName = "MyFile.pdf";
string fullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
fileName);