asp.net(c#)文件的路径表示方法

在表示路径时有两大体系:

         1、在windows下表示文件的位置,用反斜杠“\”

                例如D:\EntLib4Src\Blocks\Data\Src\Configuration.Design\  ConnectionStringEditor.cs

         2、在.Net中web开发时表示文件路径:

         常用的符号含义及举例如下:

          注:网站所在的解决方案的物理路径是:E:\demo\路径相关\demo

                   网站文件所在的文件夹的物理路径是:E:\demo\路径相关\demo\WebSite

   

          ~/在runat=server的控件中,自动的被解析为Request.ApplicationPath的值,是当前应用程序级程序的目录     在例子中是:/WebSite

          ./或者什么都不写:表示当前目录,./teacup.jpg和teacup.jpg都表示当前网页所在目录下的teacup.jpg文件

         ../表示上一层目录,比如http://www.cnblogs.com/../teacup.jpg就表示当前网页所在目录的上三层的目录下的一个teacup.jpg文件,

          /表示根目录,一般表示为:系统盘下的Inetpub\wwwroot

应用举例:

 

/*********************************************************************************

   **  IIS homedirctory在c:\inetpub\wwwroot         **

   **  虚拟目录在E:\WebApplication10.           **

   **  目前的程序在E:\WebApplication10\tmp文件夹下的一个页面.     **

   *********************************************************************************/

   string str = Server.MapPath("~/languages.xml");

   //str=E:\WebApplication10\languages.xml

   string str1 = Server.MapPath("./languages.xml");

   //str1=E:\WebApplication10\tmp\languages.xml

   string str2 = Server.MapPath("../languages.xml");

   //str2=E:\WebApplication10\languages.xml

   string str3 = Server.MapPath("mm/languages.xml");

   //str3=E:\WebApplication10\tmp\mm\languages.xml

   string str4 = Server.MapPath("/mm/languages.xml");

   //str4=c:\inetpub\wwwroot\mm\languages.xml

原文地址:https://www.cnblogs.com/ycxyyzw/p/1996349.html