原文:【转载】ASP.NET获取路径的方法

HttpContext.Current.Request.PhysicalPath;    // 获得当前页面的完整物理路径.比如

F:\XFU.NSQS\project\website\Default.aspx
HttpContext.Current.Request.PhysicalApplicationPath; // 获得当前程序运行的物理路径比

如F:\XFU.NSQS\project\website\
HttpContext.Current.Server.MapPath(@"\"); 这个就是在页面中的MapPath了.一样用法

HttpRuntime.AppDomainAppPath //这个是新发现的,很好用.

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

以用
System.AppDomain.CurrentDomain.BaseDirectory

网站在服务器磁盘上的物理路径: HttpRuntime.AppDomainAppPath
虚拟程序路径: HttpRuntime.AppDomainAppVirtualPath

HttpContext.Current.Request.ApplicationPath虚拟应用程序根路径
HttpContext.Current.Server.MapPath(".")当前的绝对路径
HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath)系统的

根目录

sb.Append(string.Format("当前请求的虚拟路径: {0}",Server.HtmlEncode

(Request.CurrentExecutionFilePath)));
        sb.Append(string.Format("获取当前应用程序的根目录路径: {0}",

Server.HtmlEncode(Request.ApplicationPath)));
        sb.Append(string.Format("当前请求的虚拟路径: {0}",Server.HtmlEncode

(Request.FilePath)));
        sb.Append(string.Format("当前请求的虚拟路径: {0}",Server.HtmlEncode

(Request.Path)));
        sb.Append(string.Format("获取当前正在执行的应用程序的根目录的物理文件系统路径:

{0}", Server.HtmlEncode(Request.PhysicalApplicationPath)));
        sb.Append(string.Format("获取与请求的 URL 相对应的物理文件系统路径: {0}",

Server.HtmlEncode(Request.PhysicalApplicationPath)));

当前请求的虚拟路径: /aDirectory/Sample/responseHtml.aspx
获取当前应用程序的根目录路径: /aDirectory
当前请求的虚拟路径: /aDirectory/Sample/responseHtml.aspx
当前请求的虚拟路径: /aDirectory/Sample/responseHtml.aspx
获取当前正在执行的应用程序的根目录的物理文件系统路径: E:\Visual Studio 2005\
获取与请求的 URL 相对应的物理文件系统路径: E:\Visual Studio 2005\\aDirectory\

sb.Append(string.Format("获取项目完整的绝对路径: {0}",

System.AppDomain.CurrentDomain.BaseDirectory.ToString()));
            //仅在尝试向此域中加载程序集之后,此属性才可用
            sb.Append(string.Format("获取项目,它由程序集冲突解决程序用来探测动态创建的

程序集: {0}", System.AppDomain.CurrentDomain.DynamicDirectory));
            sb.Append(string.Format("获取磁盘上指向应用程序目录的物理路径。: {0}",

System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath));
            sb.Append(string.Format("获取应用程序的虚拟根路径: {0}",

System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath));
            sb.Append(string.Format("获取站点的名称。: {0}",

System.Web.Hosting.HostingEnvironment.SiteName));
            //sb.Append(string.Format("获取此应用程序的虚拟路径提供程序。: {0}",

System.Web.Hosting.HostingEnvironment.VirtualPathProvider));
            sb.Append(string.Format("返回与 Web 服务器上的指定虚拟路径相对应的物理文件

路径。: {0}", Server.MapPath("sss.aspx")));

转自:http://www.cnblogs.com/zhyt1985/archive/2009/10/29/1592245.html

ASP.NET获取路径的方法的更多相关文章

  1. 【转载】ASP.NET获取路径的方法

    HttpContext.Current.Request.PhysicalPath;    // 获得当前页面的完整物理路径.比如 F:\XFU.NSQS\project\website\Default ...

  2. Java中获取路径的方法_自我分析

    就目前的我来说最常用的两种获取路径的方法是  class.getRecource(filename) 和 class.getclassloader.getRecource(filename) 这两者的 ...

  3. GetPathFromUri4kitkat【Android 4.4 kitkat以上及以下根据uri获取路径的方法】

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 在Android4.4之前和之后,通过Intent调用文件管理器选择文件,获取的文件uri地址形式是不同的. Android6.0 ...

  4. java中获取路径的方法

    在class获取路径的方法,getResource有没有“\”的区别 System.out.println("" + this.getClass().getResource(&qu ...

  5. ASP.NET获取根目录的方法集合

    编写程序的时候,经常需要用的项目根目录,自己总结如下: 1.取得控制台应用程序的根目录方法 方法1.Environment.CurrentDirectory 取得或设置当前工作目录的完整限定路径 方法 ...

  6. iOS之开发中一些相关的路径以及获取路径的方法

    模拟器的位置: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs ...

  7. Java项目中读取properties文件,以及六种获取路径的方法

    下面1-4的内容是网上收集的相关知识,总结来说,就是如下几个知识点: 最常用读取properties文件的方法 InputStream in = getClass().getResourceAsStr ...

  8. Java获取路径的方法分析详解(Application/Web)

    1.利用System.getProperty()函数获取当前路径: System.getProperty("user.dir");//user.dir用户当前的工作目录,输出:D: ...

  9. android 获取路径目录方法以及判断目录是否存在,创建目录

    Environment 常用方法: * 方法:getDataDirectory()解释:返回 File ,获取 Android 数据目录.* 方法:getDownloadCacheDirectory( ...

随机推荐

  1. 启动另外一个activity,并返回结果

    欢迎大家光临我的小店:http://clkk.taobao.com 大致步骤: 1.启动另外一个Activity,这里称子Activity: 2.子Activity通过setResult方法设置返回结 ...

  2. -sh: ./helloworld: not found

    最近在玩FriendlyARM mini2440的板子,编译了一个helloworld,通过ftp上传到开发版的文件系统中,chmod 777 helloworld,运行./helloworld,出现 ...

  3. 用Python作GIS之三:入口程序 - stargui.py

    """gui start file for Space-Time Analysis of Regional Systems#STARS的图形用户界面入口(高级用户可以直接 ...

  4. HTTP 错误 404.3 - Not Found

    在使用win2012服务器上的IIS发布网页的时候,出现下面的错误 解决办法: 将应用程序开发下的所有功能都安装. 如果上面的方法没解决问题的话,那么看看下图中的这些安装没,没有的话就继续安装.

  5. MYSQL创建多张表,相同表结构,不同表名

    #!/bin/bashfor i in {0..63}domysql -u$1 -p$2 -h127.0.0.1 <<EOFuse yoon;create table ivc_pre_de ...

  6. mysql笔记整理

    删除整个表 TRUNCATE TABLE 表名; 持久链接 自动提交

  7. C# list 筛选FindAll,根据参数过滤

    /// <summary> /// 汽车车型 获取 /// Redis Key=zgqp315_Redis_ModelNumberC_List /// </summary> / ...

  8. Http请求和响应应用

    //以下载方式打开资源 public void test4(HttpServletResponse response) throws IOException { response.setHeader( ...

  9. VBS基础篇 - 动态数组

    VBS中的动态数组需要使用System.Collections.ArrayList '建立动态数组 Dim Arrl : Set Arrl = CreateObject("System.Co ...

  10. .net 自然排序方式

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...