这篇文章主要介绍了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. org.openqa.selenium.StaleElementReferenceException

    org.openqa.selenium.StaleElementReferenceException如何解啊.什么原因造成的,貌似有时会出现,有时不会出现

  2. javascrit2.0完全参考手册(第二版) 第2章第4节 基本的数据类型

    每一个变量都有一个确定的类型表明它存储什么样的数据.js基本的数据类型有strings字符串.numbers数字.Booleans布尔类型.字符串是使用双引号或单引号包含的一串字符:数字包括整数或浮点 ...

  3. Odoo Many2many 指定默认分组过滤

    在odoo里如果想单击某个菜单打开的页面是自带过滤的,可以在打开菜单的动作中添加默认过滤来实现,今天有同学在群里问,如何在Many2many的添加更多的弹出窗口中添加类似的过滤,其实是非常非常简单的, ...

  4. png,jpg,gif格式的图片的选择

    gif:在使用动画的时候,例如加载页面时显示的预加载. png与jpg的区别: 1.png可以透明,jpg不能透明,所以需要透明的地方,必须用png.2.png是无损保存,多次保存都不会影响图片质量: ...

  5. Greenplum各种Tips(不定时更新)

    Greenplum接触也有一段时间了,在使用过程中积累了一些命令,在此分享给大家. 1. 查看segment是否有切换(没有记录则没有切换) SELECT * from gp_segment_conf ...

  6. 你应了解的4种JS设计模式

    学习地址: http://mp.weixin.qq.com/s?__biz=MjM5MTA1MjAxMQ==&mid=2651223556&idx=1&sn=8cd7a2272 ...

  7. 为Eclipse安装主题插件

    方法2:通过站点更新 eclipse:Help->Install New Software->Work with:Update Site -http://eclipse-color-the ...

  8. 深入分析 Java 中的中文编码问题

    登录 (或注册) 中文 IBM 技术主题 软件下载 社区 技术讲座 打印本页面 用电子邮件发送本页面 新浪微博 人人网 腾讯微博 搜狐微博 网易微博 Digg Facebook Twitter Del ...

  9. JSON和JS对象之间的互转(转)

    文章出处:http://www.cnblogs.com/dyllove98/p/4235909.html 1. jQuery插件支持的转换方式 $.parseJSON( jsonstr ); //jQ ...

  10. mac自定义安装nodejs步骤

    自定义安装的好处是nodejs相关的文件都在同一个文件夹下,且不与其它程序的文件混合在同一文件夹下. 1.下载node并解压缩:https://nodejs.org/dist/,选择tar.gz包下载 ...