`
Struts_Spring
  • 浏览: 105297 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Server.MapPath(path)的使用

阅读更多
用法:
1.Server.MapPath("/") 应用程序根目录所在的位置 如 C:\Inetpub\wwwroot\
2.Server.MapPath("./") 表示所在页面的当前目录
    注:等价于Server.MapPath("") 返回 Server.MapPath("")所在页面的物理文件路径
3.Server.MapPath("../")表示上一级目录
4.Server.MapPath("~/")表示当前应用级程序的目录,如果是根目录,就是根目录,如果是虚拟目录,就是虚拟目录所在的位置 如:C:\Inetpub\wwwroot\Example\
注:等效于Server.MapPath("~")。
语法:Server.MapPath(bstrLogicalPath)
作用:将 bstrLogicalPath 映射为计算机上的物理目录,注意此物理目录可以也可能不存在。
参数:bstrLogicalPath 的意思是相对目录*或虚拟目录。
疑问:bstrLogicalPath 既然既可以表示相对目录,又可以表示虚拟目录,那么它什么时候表示相对目录,什么时候表示虚拟目录呢。
规则:
当 bstrLogicalPath 以 ../ 或 ..\ 开头时,当作相对目录。 <
当 bstrLogicalPath 以斜杠开头( / 或 \ )时,从Web站点根目录(不是物理目录)的角度出发检查是否有匹配的虚拟目录(树)**,如果匹配,则当作虚拟目录,否则当作相对目录。
当 bstrLogicalPath 不以斜杠开头( / 或 \ )时,从Web站点当前目录(不是物理目录)的角度出发检查是否有匹配的虚拟目录(树)**,如果匹配,则当作虚拟目录,否则当作相对目录。
*也可以是文件。
**由于虚拟目录下面可以再建立虚拟目录,所以这里使用虚拟目录树,即:每一层的目录或虚拟目录都要与 bstrLogicalPath 中的对应目录层匹配。
***bstrLogicalPath 中含有英文点(.)或以斜杠结尾( / 或 \ )不影响上述规则。
分享到:
评论
1 楼 hautbbs 2011-11-16  
谢谢!

相关推荐

    Server.MapPath()方法(找不到路径错误的一部分)

    如果您使用的是../folder1/folder2 ...或〜/ folder1 / folder2 ...,则这些文件夹必须作为子... 因此Server.Map(path)[^]仅适用于这些情况。 但是,如果您尝试以绝对路径访问,则必须指定文件的完整路径。 其他...

    AspJpeg 2.4.0.1

    Path = Server.MapPath("images") & "\clock.jpg" 待处理图片路径 Jpeg.Open Path 打开图片 高与宽为原图片的1/2 Jpeg.Width = Jpeg.OriginalWidth / 2 Jpeg.Height = Jpeg.OriginalHeight / 2 保存图片 Jpeg....

    ASP.NET编程获取网站根目录方法小结

    Server.MapPath(Request.ServerVariables[“PATH_INFO”]) Server.MapPath(“/”) Server.MapPath(“”)//当前代码文件所在的目录路劲 Server.MapPath(“.”) Server.MapPath(“../”) Server.MapPath(“..”)  ...

    asp.net实现在线查看(预览)pdf,ppt,word,excel文件.rar

    string docExtendName = System.IO.Path.GetExtension(sourceDoc).ToLower(); bool result = false; if (docExtendName == ".pdf") { //pdf模板文件 string tempFile = Path.Combine(fileDire, "temppdf.html"...

    计数器代码

    cName=Server.MapPath("c.cnt") dName=Server.MapPath("d.cnt") Set objCountFile = objFSO.OpenTextFile(cName,1,True) If Not objCountFile.AtEndOfStream Then cnt=CLng(objCountFile.ReadAll) objCountFile....

    图片上传控件

    Directory.CreateDirectory(Path.GetDirectoryName(context.Server.MapPath(saveDir)));//建立文件夹 string fullDir = saveDir + Common.Common.GetStreamMD5(file.InputStream) + fileExtion;//将文件进行MD5...

    aspzip-组件压缩包

    zip_upFile=Server.MapPath(z_upFile) zip_infile=Server.MapPath("下载说明.txt") zip_doFile=Server.MapPath(z_doFile) zip_uptime=now() randomize zip_ranNum=int(90000*rnd)+10000 zip_ininame=year(zip_uptime...

    C# 打包 zip

    string directoryName = Path.GetDirectoryName(fullname); string fileName = Path.GetFileName(fullname); if (!Directory.Exists(directoryName)) Directory.CreateDirectory(directoryName); if (fileName !...

    aspjpeg+aspjpeg组件高级使用方法

    Path = Server.MapPath("../images/apple.jpg") '处理图片路径 Jpeg.Open Path '打开图片 '调整宽度和高度为原来的50% Jpeg.Width = Jpeg.OriginalWidth / 2 Jpeg.Height = Jpeg.OriginalHeight / 2 Jpeg.Save ...

    public static bool WriteFile(string strText.pdf

    string path = HttpContext.Current.Server.MapPath("/news/"); Encoding code = Encoding.GetEncoding("gb2312"); string temp = HttpContext.Current.Server.MapPath("/news/template.html"); StreamReader...

    Wh_BmpText

    objbmp.FontPath = server.mappath("font_12.asp") '汉字点阵字库地址 objbmp.loadBMP(server.mappath("bb.bmp")) '调用的BMP图片地址 objbmp.DrawTextWE 2,30,"网海求生者",15 '水平打印汉字DrawTextWE "X点","Y...

    FTP操作类

    string thumbnailFileName = System.IO.Path.GetFileName(gdsImg.Thumbnail); //缩略图文件名 conn.UploadFile&#40;Server.MapPath(dir&#41; + thumbnailFileName, thumbnailFileName); } catch (FtpException e...

    AspJpeg动态服务器组件v2·0注册版

     Path = Server.MapPath("../images/apple.jpg") '处理图片路径  Jpeg.Open Path '打开图片  '调整宽度和高度为原来的50%  Jpeg.Width = Jpeg.OriginalWidth / 2  Jpeg.Height = Jpeg.OriginalHeight / 2  ...

    aspnet对文件,文件夹以及xml的操作

    protected void Page_Load(object sender, EventArgs e) { string path = Server.MapPath("xiaofeng.txt"); //创建记事本xiaofeng并写入内容 FileStream fso = new FileStream(path, FileMode....

    关于模块代码

    try { if (FileUpload1.... string serverpath = Server.MapPath("images/") + filename; //string serverpath = @"d:/" + filename; FileUpload1.PostedFile.SaveAs(serverpath); this.lb_info.Text = "上传成功!";

    flvmdi,flv修复工具,针对ffgpeg+mencoder转化后的问题

    string flv_file = System.IO.Path.ChangeExtension(playFile, ".flv"); string flvmdi = Server.MapPath("../JS/videotool/flvmdi.exe"); //flvmdi修复flv进度条问题 System.Diagnostics.ProcessStartInfo ...

    ASPZIP asp打包ZIP组件

    zip_upFile=Server.MapPath(z_upFile) zip_infile=Server.MapPath("下载说明.txt") zip_doFile=Server.MapPath(z_doFile) zip_uptime=now() randomize zip_ranNum=int(90000*rnd)+10000 zip_ininame=year(zip...

    Aspose.Cells【注册文件+使用说明】

    Aspose.Cells.License li = new License(); string path = Server.MapPath("License.lic"); li.SetLicense(path); 使用时先注册控件,呵呵

    ASPJPEG学习手记

    Set Jpeg=Server.CreateObject(“Persits.Jpeg”) path=server.mappath(“s.jpg”) Jpeg.Open path Jpeg.Width=Jpeg.OriginalWidth/3 Jpeg.Height=Jpeg.originalheight /3 Jpeg.Save Server.MapPath(“cut.jpg...

    MvcItem项目

    fileName = System.IO.Path.GetFileName(fb.FileName);//获得文件的物理路径 if (string.IsNullOrEmpty(fileName)) { throw new Exception("请添加上传文件!"); } //用年月日时分秒作为文件名,并加上文件的...

Global site tag (gtag.js) - Google Analytics