string path = new directoryinfo("../").fullname;//当前应用程序路径的上级目录

获取当前目录可以使用appdomain.currentdomain.basedirectory。

获取当前目录的上级目录path.getfullpath("..")

代码

using system;

using system.collections.generic;

using system.linq;

using system.text;

using system.io;

namespace pathtest

{

class program

{

static void main(string[] args)

{

//使用appdomain获取当前应用程序集的执行目录

string dir = appdomain.currentdomain.basedirectory;

string info = string.format("appdomain方法获取当前程序集目录:{0}", dir);

console.writeline(info);

//使用path获取当前应用程序集的执行的上级目录

dir = path.getfullpath("..");

info = string.format("path方法获取当前程序集上级目录:{0}", dir); (www.111cn.net)

console.writeline(info);

//使用path获取当前应用程序集的执行目录的上级的上级目录

dir = path.getfullpath(@"....");

info = string.format("path方法获取当前程序集目录的级的上级目录:{0}", dir);

console.writeline(info);

//使用path获取当前应用程序集的执行目录的上级目录

dir = path.getfullpath(@"......");

info = string.format("path方法获取当前程序集目录的上级目录的上级目录:{0}", dir);

console.writeline(info);

//在当前程序集目录中添加指定目录

dir = path.getfullpath(@"io");

info = string.format("在当前程序集目录中添加指定目录:{0}", dir);

console.writeline(info);

console.read();

}

}

}

winform比较复杂,我只知道environment.currentdirectory是当前exe的路径,你要得到上一级的再用这个路径算。
asp教程.net就比较简单了,直接../就行了

如果是asp.net教程就 server.mappath("~/bg/")就可以了。
from:http://www.111cn.net/net/net/37071.htm

asp.net与C# path.GetFullPath 获取上级目录的更多相关文章

  1. C#的path.GetFullPath 获取上级目录实现方法

    这篇文章主要介绍了C#的path.GetFullPath 获取上级目录实现方法,包含了具体的C#实现方法以及ASP.net与ASP等的方法对比,非常具有实用价值,需要的朋友可以参考下   本文实例讲述 ...

  2. os.path.join合并 os.path.dirname返回上一级目录 os.path.exists(path) os.stat('path/filename')获取文件/目录信息

    import os str1 = "grsdgfd" str2 = "wddf" str3 = "gddgs" # print(str1 + ...

  3. window 批处理脚本获取上级目录

    1 SET CurrDir=%CD% CD.. SET InstPath=%CD% CD %CurrDir% 2 pushd.. set parent=%cd% popd 参考: https://ms ...

  4. c#上级目录

    本文实例讲述了C#的path.GetFullPath 获取上级目录实现方法,分享给大家供大家参考.具体实现方法如下: string path = new directoryinfo("../ ...

  5. python 获取当前目录,上级目录,上上级目录

    import os print '***获取当前目录***' print os.getcwd() print os.path.abspath(os.path.dirname(__file__)) pr ...

  6. Python学习笔记_获取当前目录和上级目录

    实验目标:获取当前目录和上级目录 系统环境: 1.OS:Win10 64位 2.Pythoh 3.7 3.实验路径:C:\Work\Python\MergeExcel 代码参考: # -*- codi ...

  7. Python基础-获取当前目录,上级目录,上上级目录

    import os print '***获取当前目录***' print os.getcwd() print os.path.abspath(os.path.dirname(__file__)) pr ...

  8. os:获取当前目录路径,上级目录路径,上上级目录路径

    import os '''***获取当前目录***''' print(os.getcwd()) print(os.path.abspath(os.path.dirname(__file__))) '' ...

  9. 【转载】ASP.NET中Server.MapPath方法获取网站根目录总结

    在ASP.NET网站应用程序中,可以通过Server.MapPath方法来获取跟服务器有关的目录信息,如获取网站的根目录.获取当前代码文件所在的目录路径.获取当前代码所在路径的上级路径等.Server ...

随机推荐

  1. JavaScript 之 动态加载JS代码或JS文件

    2.动态加载JS文件 <script type="text/javascript"> function loadScript(url, callback) { var ...

  2. javascript将算法复杂度从O(n^2)做到O(n)

    compare the difference of two giving array, return results: 1. elements in both array, 2. elements o ...

  3. 火狐浏览器flash经常奔溃的

    火狐浏览器flash经常奔溃的 1.首先,在火狐浏览器地址栏在输入:about:config?filter=dom.ipc.plugins.flash.disable-protected-mode,按 ...

  4. 微信小程序图片上传并展示

    1.首先编写微信小程序的页面和样式: index.js var total = []; Page({ data: { perImgSrc: [] }, onLoad: function (option ...

  5. px 和 em 的区别

    相同点:px和em都是长度单位: 异同点:px的值是固定的,指定是多少就是多少,计算比较容易.em得值不是固定的,并且em会继承父级元素的字体大小.浏览器的默认字体高都是16px.所以未经调整的浏览器 ...

  6. 【Linux】常见Linux默认的shell

    常见的操作系统下的shell: Linux下默认的shell是Bourne Again shell(bash) Solaris和FreeBSD下默认的是Bourne shell(sh) AIX系统下默 ...

  7. java 自增和自减运算符

    /** 自增和自减运算符: ++: 如果是++b,则表示先对变量b+1,再执行其他的操作: 如果是b++,则表示先执行表达式操作,再对变量自身+1 --: 用法和++相同 */ //Test.java ...

  8. PHP 反射API说明

    2.API概览:class Reflection { }interface Reflector { }class ReflectionException extends Exception { }cl ...

  9. linux mysql 数据库开启外部访问设置指南

    Linux下设置MySQL和允许外部机器访问,具体目录是具体情况而定,有的人是安装了在个人目录下,则找到对应的目录则可以 Linux下设置MySQL和允许外部机器访问sudo vi /etc/my.c ...

  10. weblogic10.3.6打补丁PSU

    weblogic的补丁,非付费不能下载... Oracle WebLogic Server Patch Set Update 10.3.6.0.170418 PATCH_ID - RVBS    #补 ...