zoukankan      html  css  js  c++  java
  • Server.MapPath()获取绝对路径

    1.    Server.MapPath("/")  应用程序根目录所在的位置 如

    C:Inetpubwwwroot

    2.Server.MapPath("./")  表示所在页面的当前目录 
          注:等价于Server.MapPath("")  返回 Server.MapPath("")所在页面的物理文件路径
          3.Server.MapPath("../")表示上一级目录 
          4.Server.MapPath("~/")表示当前应用级程序的目录,如果是根目录,就是根目录,如果是虚拟目录,就是虚拟目录所在的位置如:   

    C:InetpubwwwrootExample
         注:等效于Server.MapPath("~"),即相对路径

    Java代码 :
    string filename=Server.MapPath("./") + @"Web.config";   
    string filename=Server.MapPath("./") + "/Web.config";   
    string filename=Server.MapPath("") + @"Web.config"  

    string filename=Server.MapPath("./") + @"Web.config";

    string filename=Server.MapPath("./") + "/Web.config";

    string filename=Server.MapPath("") + @"Web.config"

    string Server.MapPath(string path)
    ��返回与Web服务器上的指定虚拟路径相对应的物理文件路径。�

    Html代码 
    <%=Server.MapPath(Request.ServerVariables["PATH_INFO"])%>  
      
    �<%= Server.MapPath("/")%>  
    ��<%= Server.MapPath("")%>  
    ��<%=Server.MapPath(".")%>  
      
    ��<%= Server.MapPath("../")%>  
    ��<%= Server.MapPath("..")%>��  

    <%=Server.MapPath(Request.ServerVariables["PATH_INFO"])%> 

    ��<%= Server.MapPath("/")%>

    ��<%= Server.MapPath("")%>

    ��<%=Server.MapPath(".")%> 

    ��<%= Server.MapPath("../")%>

    ��<%= Server.MapPath("..")%>�� 
    �以上的代码在http://localhost/EnglishClub/manage/WebForm1.aspx页面
    ��运行结果:
    ��C:InetpubwwwrootEnglishClubmanageWebForm1.aspx
    ��
    ��C:Inetpubwwwroot
    ��C:InetpubwwwrootEnglishClubmanage
    ��C:InetpubwwwrootEnglishClubmanage
    ��
    ��C:InetpubwwwrootEnglishClub
    ��C:InetpubwwwrootEnglishClub

  • 相关阅读:
    数组和链表
    IAP升级
    使用Git和Github来管理自己的代码和笔记
    Eeprom和Flash的区别
    程序员的七种武器
    数据结构和算法的关系
    STVD、IAR两种编译器比较
    STM32与STM8操作寄存器的区别
    Linux用户身份与文件权限
    地图缩放到指定经纬度
  • 原文地址:https://www.cnblogs.com/donchen/p/3944728.html
Copyright © 2011-2022 走看看