The solution mainly relies on httpcontext objects, such
Httpcontext. current. request. physicalpath; // obtain the complete physical path of the current page. For example, f: xfu. nsqsprojectwebsitedefault. asp tutorial x
Httpcontext. current. request. physicalapplicationpath; // obtain the physical path of the current program running, such as f: xfu. nsqsprojectwebsite
Httpcontext. current. server. mappath (@ ""); this is the mappath in the page.
Httpruntime. appdomainapppath // This is a newly discovered and useful method.
Another method is to call the dll file in the asp.net tutorial. If you want to know the working directory of the current web site, you can use
System. appdomain. currentdomain. basedirectory
Three simple methods
When Xi asp.net uploads a file, it finds that there are three methods to obtain the physical path of the current web program directory:
Method 1:
String spath = system. io. path. getdirectoryname (page. request. physicalpath)
Method 2:
String spath = system. web. httpcontext. current. request. mappath ("images /")
// ("Images/") is any directory under the current virtual directory
Method 3:
String spath = page. server. mappath ("images/"); // ("images/") is any directory in the current virtual directory
Also: get the file name in the full path
String sfile = system. io. path. getfilename (sfile );
// Obtain the complete path of the current process, including the file name (process name ).
String str = this. gettype (). assembly. location;
Result: x: xxxxxxxxx.exe (.exefile)
// Obtain the complete path of the new process component and associate it with the active process, including the file name (process name ).
String str = system. diagnostics. process. getcurrentprocess (). mainmodule. filename;