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. 【转】Java四种线程池的使用

    Java通过Executors提供四种线程池,分别为:newCachedThreadPool创建一个可缓存线程池,如果线程池长度超过处理需要,可灵活回收空闲线程,若无可回收,则新建线程.newFixe ...

  2. ionic3+angular5页面间传递参数

    一.从一个页面跳转到另一个页面的方法 1.引入服务 import { NavController } from 'ionic-angular'; 2.初始化 constructor(public na ...

  3. ZH奶酪:PHP的cURL库

    原文链接:http://coolshell.cn/articles/664.html 参考链接:http://www.runoob.com/php/php-ref-curl.html 使用PHP的cU ...

  4. 微信小程序 - 自定义swiper dots样式(非组件)

      自定义须知: :组件内无法使用自定义样式变化,需要自定义 :原理就是利用swiper change事件与下标index匹配,显示不同的样式 swiper组件须知: :一旦swiper用于组件化,就 ...

  5. Fibre Channel address weaknesses

    http://searchitchannel.techtarget.com/feature/Fibre-Channel-address-weaknesses Figure 2.1 Five layer ...

  6. SLF4J warning or error messages and their meanings

    来自:http://www.slf4j.org/codes.html#StaticLoggerBinder The method o.a.commons.logging.impl.SLF4FLogFa ...

  7. python2和python3网络访问包

    python3 import http.client import urllib.parse python2 import httplib import urllib

  8. python获取系统开机时间

    import psutil import time time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(psutil.boot_time()))

  9. 开源 JSON 库解析性能对比( Jackson / Json.simple / Gson )

    Json 已成为当前服务器与 web 应用之间数据传输的公认标准. 微服务及分布式架构经常会使用 Json 来传输此类文件,因为这已经是 webAPI 的事实标准. 不过正如许多我们习以为常的事情一样 ...

  10. Flink官网文档翻译

    http://ifeve.com/flink-quick-start/ http://vinoyang.com/2016/05/02/flink-concepts/ http://wuchong.me ...