asp.net与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.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 获取上级目录的更多相关文章
- C#的path.GetFullPath 获取上级目录实现方法
这篇文章主要介绍了C#的path.GetFullPath 获取上级目录实现方法,包含了具体的C#实现方法以及ASP.net与ASP等的方法对比,非常具有实用价值,需要的朋友可以参考下 本文实例讲述 ...
- os.path.join合并 os.path.dirname返回上一级目录 os.path.exists(path) os.stat('path/filename')获取文件/目录信息
import os str1 = "grsdgfd" str2 = "wddf" str3 = "gddgs" # print(str1 + ...
- window 批处理脚本获取上级目录
1 SET CurrDir=%CD% CD.. SET InstPath=%CD% CD %CurrDir% 2 pushd.. set parent=%cd% popd 参考: https://ms ...
- c#上级目录
本文实例讲述了C#的path.GetFullPath 获取上级目录实现方法,分享给大家供大家参考.具体实现方法如下: string path = new directoryinfo("../ ...
- python 获取当前目录,上级目录,上上级目录
import os print '***获取当前目录***' print os.getcwd() print os.path.abspath(os.path.dirname(__file__)) pr ...
- Python学习笔记_获取当前目录和上级目录
实验目标:获取当前目录和上级目录 系统环境: 1.OS:Win10 64位 2.Pythoh 3.7 3.实验路径:C:\Work\Python\MergeExcel 代码参考: # -*- codi ...
- Python基础-获取当前目录,上级目录,上上级目录
import os print '***获取当前目录***' print os.getcwd() print os.path.abspath(os.path.dirname(__file__)) pr ...
- os:获取当前目录路径,上级目录路径,上上级目录路径
import os '''***获取当前目录***''' print(os.getcwd()) print(os.path.abspath(os.path.dirname(__file__))) '' ...
- 【转载】ASP.NET中Server.MapPath方法获取网站根目录总结
在ASP.NET网站应用程序中,可以通过Server.MapPath方法来获取跟服务器有关的目录信息,如获取网站的根目录.获取当前代码文件所在的目录路径.获取当前代码所在路径的上级路径等.Server ...
随机推荐
- C# list与数组互相转换
1,从System.String[]转到List<System.String>System.String[] str={"str","string" ...
- SQL到NoSQL概览性总结之一 数据库应用场景选型
数据库类型与实例 适合场景 不适合场景 场景举例 关系数据库 基于集合理论,具有行和列的二维表,严格使用类型 开源MySQL/MariaDB, PostgreSQL 商业:Oracle,DB2,SQL ...
- Nginx+Lua+Redis构建高并发应用
一. 源文来自:http://www.ttlsa.com/nginx/nginx-lua-redis/ 二. 预览如下:
- 代码实现分析mpeg-2文件
1.概述 把上一篇文章中讲到的mpeg-2文件结构分析用代码实现,结合mpeg-2文件分析.才easy看懂. 2.代码 /* *本程序主要分析MPEG-2文件 *作者:缪国凯(MK) *8214860 ...
- V-rep学习笔记:vrep中的实用工具
在V-REP的模型浏览器中可以找到一个工具文件夹tools,点开后会在下面一栏中显示许多方框图,将这些方框拖到场景模型中可以实现一些特定的功能,方便建模或其它操作. Center of mass vi ...
- 6、redis之使用spring-data-redis的Template
POM: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.o ...
- 【转】 mysql反引号的使用(防冲突)
转载地址:http://blog.itechol.com/space.php?uid=33&do=blog&id=6681 1.mysql语句中 反引号 [`]作用: 避免表明.字段名 ...
- Tensorflow get_variable和Varialbe的区别
import tensorflow as tf """ tf.get_variable()和Variable有很多不同点 * 它们对重名操作的处理不同 * 它们受name ...
- iOS 自动布局框架 – Masonry 详解
目前iOS开发中大多数页面都已经开始使用Interface Builder的方式进行UI开发了,但是在一些变化比较复杂的页面,还是需要通过代码来进行UI开发的.而且有很多比较老的项目,本身就还在采用纯 ...
- ReactiveCocoa 中 RACSignal 是怎样发送信号
前言 ReactiveCocoa是一个(第一个?)将函数响应式编程范例带入Objective-C的开源库.ReactiveCocoa是由Josh Abernathy和Justin Spahr-Summ ...