码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2014-10-27 22:40:24      阅读:419      评论:0      收藏:0      [点我收藏+]

标签:winform   http   io   ar   使用   for   sp   on   cti   

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.111cn.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/")就可以了。
from:http://www.111cn.net/net/net/37071.htm

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

标签:winform   http   io   ar   使用   for   sp   on   cti   

原文地址:http://www.cnblogs.com/alibai/p/4055212.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!