using Server MapPath method.
Let us try some examples where different conditions we will apply to see the results. We kept the file mappath.asp inside my_file directory. So our total physical path looks like this.
Note that the object Server.MapPath does not check the existence of actual path, it only maps the given path along with the physical path. So any error in writing directory name or file name will not result in any error message. To make this point clear we are starting with one example of test.asp which is not existing inside the my_file directory. Here is the command and the output
The output of the above line is here
Here we have kept the code inside mappath.asp file and it has displayed the above line. Now let us try with different files and names , the output of the code is given in italic font.
With or without “/” or “\” mark at the staring of the path
If the file or directory name starts with / or \ then the path is taken as full virtual and it starts from server root. Otherwise it is considered from the path of the file being executed. Here are some examples with outputs shown in Italics.
Note the difference the \ mark at the staring of the file name has done. It has taken the root of the server even though the current script is executed inside my_files directory.
To get the root of the present script running we have to use like this.
To get the server root we have to use