Csharp/C#教程:C#的path.GetFullPath 获取上级目录实现方法分享

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

代码如下:stringpath=newdirectoryinfo(“../”).fullname;//当前应用程序路径的上级目录
获取当前目录可以使用代码如下:appdomain.currentdomain.basedirectory
获取当前目录的上级目录代码如下:path.getfullpath(“..”)

具体代码如下:
代码如下:usingsystem;
usingsystem.collections.generic;
usingsystem.linq;
usingsystem.text;
usingsystem.io;
namespacepathtest
{
classprogram
{
staticvoidmain(string[]args)
{
//使用appdomain获取当前应用程序集的执行目录
stringdir=appdomain.currentdomain.basedirectory;
stringinfo=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#获取指定目录最后写入时间的方法C#获取项目指定目录下文件的方法C#获取目录最后访问时间的方法C#常用目录文件操作类实例C#下实现创建和删除目录的实例代码C#递归查找树状目录实现方法C#使用Directoryinfo类获得目录信息和属性的方法

标签: ul 方法 pat path

C#遍历DataSet控件实例上述就是C#学习教程:C#的path.GetFullPath 获取上级目录实现方法分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/905848.html

(0)
上一篇 2021年10月23日
下一篇 2021年10月23日

精彩推荐