C#中的相对路径与决定路径

相对路径

      System.Environment.CurrentDirectory;  
      Application.StartupPath;         //   不包括程序名  
      Application.ExecutablePath;   //   包括程序名  

 

      ExecutablePath的值为:

      C:\Documents and Settings\tfq\My Documents\Visual Studio 2005\Projects\TeleServer\TeleServer\bin\Debug\TeleServer.exe,

      而CurrentDirectory和StartupPath的值为:

      C:\Documents and Settings\tfq\My Documents\Visual Studio 2005\Projects\TeleServer\TeleServer\bin\Debug

绝对路径

   用 System.IO.FileInfo   

    using   System;  
    using   System.IO;  
   
   FileInfo   fi   =   new   FileInfo(path);   //这里的path是相对路径
   if   (fi.Exists)  
   Console.WriteLine(fi.FullName);             //这个fullName就是绝对路径
   
  用 ASP.NET
  String   sFullPath   =   Server.MapPath(path);

posted @ 2011-09-14 22:40  园博客  阅读(581)  评论(0编辑  收藏  举报