【www.gdgbn.com--php应用】

winfom获取应用程序当前路径
system.diagnostics.process.getcurrentprocess().mainmodule.filename;
//获取新的 process 组件并将其与当前活动的进程关联的主模块的完整路径,包含文件名(进程名)。
//返回 e:c#学习获取当前路径获取当前路径bindebug获取当前路径.exe system.appdomain.currentdomain.setupinformation.applicationbase;
//获取和设置包含该应用程序的目录的名称。
//返回 e:c#学习获取当前路径获取当前路径bindebug
system.windows.forms.application.startuppath;
//获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称。
//返回 e:c#学习获取当前路径获取当前路径bindebug
system.windows.forms.application.executablepath;
//获取启动了应用程序的可执行文件的路径,包括可执行文件的名称。
//返回 e:c#学习获取当前路径获取当前路径bindebug获取当前路径.exe system.io.directory.getcurrentdirectory();
//获取应用程序的当前工作目录(不可靠)。
//返回 e:c#学习获取当前路径获取当前路径bindebug
this.gettype().assembly.location;
//获取当前进程的完整路径,包含文件名(进程名)。
//遗憾的静态方法无法使用
//返回 e:c#学习获取当前路径获取当前路径bindebug获取当前路径.exe

 

string path = "";   if (system.environment.currentdirectory == appdomain.currentdomain.basedirectory)//windows应用程序则相等  {  path = appdomain.currentdomain.basedirectory;  } else  {   path = appdomain.currentdomain.basedirectory + "bin";   }

c# webform 文件访问

string[] getdirectoryfiles(string dirvpath, string pattern)
        {
            string dirvpathrooted = string.concat(
                httpcontext.current.request.applicationpath.tolower(),
                dirvpath);
            string dirpath = httpcontext.current.server.mappath(dirvpathrooted);

            string[] files = directory.getfiles(dirpath, pattern, searchoption.alldirectories);
            string[] includes = new string[files.length];
            for (int i = 0; i < files.length; i++)
            {
                includes[i] = files[i]
                    .replace(dirpath, dirvpath) // replace physical root by virtual root
                    .replace("", "/");
            }
            return includes;
        }

本文来源:http://www.gdgbn.com/jiaocheng/29878/