您现在的位置: 万盛学电脑网 >> 程序编程 >> 网络编程 >> 编程语言综合 >> 正文

C#中获取路径的几种方法

作者:佚名    责任编辑:admin    更新时间:2022-06-22

   1. 在.Net中web开发时

  (1) ~/在runat=server的控件中会自动被解析为Request.ApplicationPath的值,是当前应用程序的目录 如

C#中获取路径的几种方法 三联

  ~/userCommunity/index.aspx则对应为/HENU.RCenter.Internal/UserCommunity

  (2) ./表示当前目录

  (3)../表示上一层目录 如UserCommunity文件夹下的文件中可以以:../module/来访问module中的文件

  2 获取当前请求页面的路径:Request.FilePath

  3 获取项目下的文件路径:

  string path=AppDomain. CurrentDomain .SetUpInformation.ApplicationBase+文件夹+文件

  如获取项目下的temp文件夹下文件的路径

  可以用:string savePath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "temp" + @"" + filename

  4 Server.MapPath用法:

  若在项目下Content文件夹下的UserInfoManager.aspx代码中写如下路径

  this.tempPath = Server.MapPath("UploadResourceImage");

  则返回 D:wxm练习ContentUploadResourceImage