The main solution is to rely on HttpContext objects, such as
Httpcontext.current.request.physicalpath; Gets the full physical path of the current page. For example f:xfu.nsqsprojectwebsitedefault.asp Tutorial X
Httpcontext.current.request.physicalapplicationpath; Get the physical path that the current program is running, like F:xfu.nsqsprojectwebsite.
Httpcontext.current.server.mappath (@ ""); This is the MapPath on the page. Same usage
Httpruntime.appdomainapppath//This is newly discovered, very easy to use.
Another is to handle calling DLL files in the ASP.net tutorial, and DLL files that want to know the working directory of the current Web site can use
System.appdomain.currentdomain.basedirectory
Simple Three Ways
Xi asp.net upload file, found that there are three ways to get the current web directory physical path:
Method One:
string spath = System.io.path.getdirectoryname (Page.request.physicalpath)
Method Two:
string spath = System.web.httpcontext.current.request.mappath ("images/")
("images/") is any directory under the current virtual directory
Method Three:
string spath = Page.server.mappath ("images/"); ("images/") is any directory under the current virtual directory
Another: Get the file name in the full path
string sfile = System.io.path.getfilename (sfile);
Gets the full path of the current process, including the filename (process name).
string str = This.gettype (). assembly.location;
Result:x:xxxxxxxxx.exe (. exe file directory +.exe file name)
Gets the full path of the main module that is associated with the currently active process, including the filename (process name), for the new process component.
string str = system.diagnostics.process.getcurrentprocess (). Mainmodule.filename;