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

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

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.jb51.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/")就可以了。

希望本文所述对大家的C#程序设计有所帮助。

C#的path.GetFullPath 获取上级目录实现方法的更多相关文章

  1. asp.net与C# path.GetFullPath 获取上级目录

    string path = new directoryinfo("../").fullname;//当前应用程序路径的上级目录 获取当前目录可以使用appdomain.curren ...

  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. php获取父目录的方法 dirname()

    dirname() 方法,获取父目录的方法,官方文档:http://php.net/manual/en/function.dirname.php 在 php 7.0 后,dirname() 支持两个参 ...

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

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

  5. 【转】MFC获取程序目录路径方法

    原文网址:http://yeahyuanqing.blog.163.com/blog/static/118025091201149480818/ MFC获得当前应用程序目录的GetCurrentDir ...

  6. href中使用相对路径访问上级目录的方法

    项目ProjectXXX目录如下: WebContent> hello.jsp Folder1> foo.jsp Folder2> foo2.jsp 在foo.jsp中访问hello ...

  7. 【ASP.NET】获取网站目录的方法

         获取网站物理路径: HttpRuntime.AppDomainAppPath 获取网站虚拟路径: HttpRuntime.AppDomainAppVirtualPath

  8. c#上级目录

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

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

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

随机推荐

  1. About_AJAX

    Asynchronous JavaScript And XML (1)AJAX大多用于验证和分页: (2)首先要激活(对象): window.ActiveXObject(针对IE): window.X ...

  2. 详解CALayer 和 UIView的区别和联系

    详解CALayer 和 UIView的区别和联系   前言 前面发了一篇iOS 面试的文章,在说到 UIView 和 CALayer 的区别和联系的时候,被喵神指出没有切中要点,所以这里就 CALay ...

  3. 粉笔网iPhone端使用的第三方开源库

    粉笔网iPhone端使用的第三方开源库 前言 最近有朋友问我粉笔网 iPhone 端使用了哪些第三方的开源库.我在这儿整理了一下,分享给大家. ASIHttpRequest ASIHttpReques ...

  4. [LintCode] Add and Search Word 添加和查找单词

    Design a data structure that supports the following two operations: addWord(word) and search(word) s ...

  5. Java 多继承

    浅浅地上了几天 Java 的课程,然后怎么也想不明白:Java 不支持多继承有和接口到底是什么样的关系? 一只牛的故事. // 叫的抽象基类 abstract class call{ } // 跑的抽 ...

  6. win10添加打印机--无法访问指定设备,路径或文件。。

    win10添加打印机无法访问指定设备,路径或文件..后来发现很多按钮点击多说无法访问指定设备,路径或文件.. 解决添加打印机问题: 在搜索栏中搜索:print (从这里添加) 彻底解决: 添加环境变量 ...

  7. Daily Scrum 10.27

    今天是星期天,但大家都没有放松,还是抽出了一定的时间来完成任务.可以感觉出来在编译作业的压力下大家的热情不是很高涨,希望大家坚持下去. 下面是今天的Task统计: 下面是所有迭代的状态:

  8. poj 2325 Persistent Numbers

    简单的贪心和高精度运算,主要还是要读懂题. #include"iostream" #include"stdio.h" #include"string& ...

  9. MarkMan – 马克鳗,让设计更有爱!

    scavin(Google+) on 2010.11.16. MarkMan – 马克鳗 是一款方便高效的标注工具,极大节省设计师在设计稿上添加和修改标注的时间,让设计更有爱.Adobe AIR 平台 ...

  10. 集中式版本控制VS分布式版本控制

    CVS及SVN都是集中式的版本控制系统,而Git是分布式版本控制系统,集中式和分布式版本控制系统有什么区别呢? 集中式版本控制系统,版本库是集中存放在中央服务器的,而干活的时候,用的都是自己的电脑,所 ...