server.mappath()
来源:互联网 发布:aegisub 中文版 mac 编辑:程序博客网 时间:2024/06/17 08:59
/网站主目录
../上层目录
~/网站虚拟目录
Server.MapPath()的命名空间:
System.Web.HttpContext.Current.Server.MapPath
Server.MapPath()代码示例:
/* 下面是一段我连接access数据库时常用的代码,其中Server.MapPath("datebase/date.mdb")是表示将 datebase/date.mdb的相对路径转换为绝对路径.如果date.mdb文件在D:\datebase下那么我们通过 Server.MapPath获取的到路径则是D:\datebase\date.mdb*/
strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
+Server.MapPath("datebase/date.mdb");
Server.MapPath("/") //返回应用程序根目录所在的位置 如 C:\Inetpub\wwwroot\
Server.MapPath("~") //表示当前应用级程序的目录,如果是根目录,就是根目录,如果是虚拟目录,就是虚拟目录所在的位置 如:C:\Inetpub\wwwroot\Example\
注:等效于Server.MapPath("~")。
Server.MapPath("./") //返回当前目录绝对路径
Server.MapPath("../") //返回上一级目录的绝对路径
Server.MapPath()讲来讲去的作用就是 将相对路径转换为绝对路径。
以下再举几个我们常见的Server.MapPath的示例:
如果当前的网站目录为E:\wwwroot 应用程序虚拟目录为E:\wwwroot\company 浏览的页面路径为E:\wwwroot\company\news\show.asp
在show.asp页面中使用
Server.MapPath("./") 返回路径为:E:\wwwroot\company\news
Server.MapPath("/") 返回路径为:E:\wwwroot
Server.MapPath("../") 返回路径为:E:\wwwroot\company
Server.MapPath("~/") 返回路径为:E:\wwwroot\company
另:
如果你从Page类继承的类中执行这条语句,才可以简单地使用
DataBase = Server.MapPath("data.mdb");
否则写全命名空间:System.Web.HttpContext.Current.Server.MapPath();
注意:如果是在一个类库下的一个类中、要先添加引入using System.Web;因为新建一个类库时默认是不引入using System.Web的!
- Server.MapPath()
- Server.MapPath
- Server.MapPath
- Server.MapPath()
- Server.MapPath()
- Server.MapPath
- Server.MapPath(".") Server.MapPath("./") Server.MapPath("/") Server.MapPath用法详解
- server .mappath
- SERVER.MapPath()
- Server.MapPath()
- Server.MapPath()
- Server.MapPath()
- Server.MapPath()
- Server.MapPath()
- Server.MapPath()
- Server.MapPath()
- Server.MapPath()
- Server.MapPath
- ununtu 如何安装源文件
- ubuntu查看apt-get里面都提供了哪些软件
- ubuntu 显示隐藏的文件
- JS+AS实现真正页面加载图片进度条(带百分比)
- ununtu 安装软件的方法有哪些
- server.mappath()
- ubuntu如何将英文版本的系统改成中文版本
- ubuntu关于桌面特效
- ubuntu各版本的意义
- linux学习笔记——过滤器
- ubuntu 不能被远程怎么办
- JavaScript延时函数
- ubuntu -超级管理员root 登录
- ubuntu 11.10如何显示图形界面