zoukankan      html  css  js  c++  java
  • C#IOPath类path.GetFullPath 获取上级目录实现方法

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

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

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

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

    获取当前目录可以使用

     1 appdomain.currentdomain.basedirectory 

    获取当前目录的上级目录

    1 path.getfullpath("..")

    具体代码如下:

     1 using system;
     2 using system.collections.generic;
     3 using system.linq;
     4 using system.text;
     5 using system.io;
     6 namespace pathtest
     7 {
     8 class program
     9 {
    10 static void main(string[] args)
    11 {
    12 //使用appdomain获取当前应用程序集的执行目录
    13 string dir = appdomain.currentdomain.basedirectory;
    14 string info = string.format("appdomain方法获取当前程序集目录:{0}", dir);
    15 console.writeline(info);
    16 //使用path获取当前应用程序集的执行的上级目录
    17 dir = path.getfullpath("..");
    18 info = string.format("path方法获取当前程序集上级目录:{0}", dir); (www.jb51.net)
    19 console.writeline(info);
    20 //使用path获取当前应用程序集的执行目录的上级的上级目录
    21 dir = path.getfullpath(@"....");
    22 info = string.format("path方法获取当前程序集目录的级的上级目录:{0}", dir);
    23 console.writeline(info);
    24 //使用path获取当前应用程序集的执行目录的上级目录
    25 dir = path.getfullpath(@"......");
    26 info = string.format("path方法获取当前程序集目录的上级目录的上级目录:{0}", dir);
    27 console.writeline(info);
    28 //在当前程序集目录中添加指定目录
    29 dir = path.getfullpath(@"io");
    30 info = string.format("在当前程序集目录中添加指定目录:{0}", dir);
    31 console.writeline(info);
    32 console.read();
    33 }
    34 }
    35 }

    复制代码

    winform比较复杂,我只知道environment.currentdirectory是当前exe的路径,你要得到上一级的再用这个路径算。
    asp就比.net简单了,直接../就行了
    如果是asp.net直接用server.mappath("~/bg/")就可以了。

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

  • 相关阅读:
    bzoj 3527: [Zjoi2014]力
    bzoj 1797: [Ahoi2009]Mincut 最小割
    bzoj 1028: [JSOI2007]麻将
    bzoj 1019: [SHOI2008]汉诺塔
    bzoj 1023: [SHOI2008]cactus仙人掌图
    bzoj 3289: Mato的文件管理
    bzoj 4034: [HAOI2015]T2
    bzoj 1218: [HNOI2003]激光炸弹
    bzoj 2431: [HAOI2009]逆序对数列
    The full stack trace of the root cause is available in the Apache Tomcat/8.0.8 logs.
  • 原文地址:https://www.cnblogs.com/grj001/p/12225313.html
Copyright © 2011-2022 走看看