这篇文章主要介绍了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. jsp实现过滤器的简单例子

    web.xml配置如下: <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns=&quo ...

  2. SpringMVC原理和框架

    SpringMVC工作原理 在上一篇章[spring]01_环境配置 中,我们演示了一个简单的HelloWorld工程. 本篇章重点讲述SpringMVC的基本工作原理,让大家进一步加深认识. 工作流 ...

  3. phpMyAdmin:无法在发生错误时创建会话,请检查 PHP 或网站服务器日志,并正确配置 PHP 安装。

    一:错误提示 英文:Cannot start session without errors, please check errors given in your PHP and/or webserve ...

  4. Log4cplus使用

    Log4cplus使用¶ 1.1 简介 log4cplus是C++编写的开源日志系统,前身是java编写的log4j日志系统.log4cplus具有线程安全.灵活.以及多粒度控制的特点,通过将信息划分 ...

  5. Android多次点击事件的监听和处理

    package com.example.administrator.mystudent.MoreClick; import android.os.SystemClock; import android ...

  6. jquery的validate.js 和 form.js 的使用方法

    在使用 Jquery 的方法的验证并且修改 原Form 表单的提交方式的时候,需要引用的文件有 <script type="text/javascript" src=&quo ...

  7. mysql远程连接提示无法连接,报1130错误

    可能是你的帐号不允许从远程登陆,只能在localhost.这个时候只要在localhost的那台电脑,登入mysql后,更改 “mysql” 数据库里的 “user” 表里的 “host” 项,从”l ...

  8. 【HDU 4747 Mex】线段数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4747 题意:有一组序列a[i](1<=i<=N), 让你求所有的mex(l,r), mex ...

  9. Jackson转换对象为json的时候报java.lang.stackoverflowerror

    无论在将一个对象转为json字符串的时候采用何种算法,如果你的对象的属性的类型不是基本类型或对应的引用类型,转换应该都不会就此结束,那么有一种方式可以导致这种转换陷入无限循环:将某个对象的属性设为对象 ...

  10. Java开发搜索引擎爬虫

    package com.peidon.html; import java.io.BufferedReader; import java.io.File; import java.io.FileOutp ...