【www.gdgbn.com--页面特效】

解决的方法主要是依靠 httpcontext 对象,比如

httpcontext.current.request.physicalpath;    // 获得当前页面的完整物理路径.比如 f:xfu.nsqsprojectwebsitedefault.asp教程x
httpcontext.current.request.physicalapplicationpath;  // 获得当前程序运行的物理路径比如f:xfu.nsqsprojectwebsite
httpcontext.current.server.mappath(@""); 这个就是在页面中的mappath了.一样用法

httpruntime.appdomainapppath //这个是新发现的,很好用.

还有一个是用来处理在asp.net教程中调用dll文件,而dll文件如果想知道当前的web站点的工作目录可以用
system.appdomain.currentdomain.basedirectory


简单三种方法

习asp.net上传文件时,发现有三种方法可以获取当前web程序目录物理路径:

方法一:

string spath = system.io.path.getdirectoryname(page.request.physicalpath)

方法二:

string spath = system.web.httpcontext.current.request.mappath("images/")

                                                             //("images/")是当前虚拟目录下的任意目录

方法三:

string spath = page.server.mappath("images/");   //("images/")是当前虚拟目录下的任意目录

另:获取全路径中的文件名

string sfile = system.io.path.getfilename(sfile);

 

//获取当前进程的完整路径,包含文件名(进程名)。

string str = this.gettype().assembly.location;

result: x:xxxxxxxxx.exe (.exe文件所在的目录+.exe文件名)

//获取新的 process 组件并将其与当前活动的进程关联的主模块的完整路径,包含文件名(进程名)。

string str = system.diagnostics.process.getcurrentprocess().mainmodule.filename;

 

本文来源:http://www.gdgbn.com/wangyetexiao/28656/