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 ...
随机推荐
- JavaScript编程(终极篇)
JavaScript 实现是由以下 3 个不同部分组成的: 核心(ECMAScript) 文档对象模型(DOM) 浏览器对象模型(BOM) 1.数据类型 typeof 运算符 对变量 ...
- 使用Spring框架入门三:基于XML配置的AOP的使用
一.引入Jar包 <!--测试1使用--> <dependency> <groupId>org.springframework</groupId> &l ...
- 【Linux】创建不可修改文件
有时候,我们害怕别人修改我们创建的文件,或者是误删我们创建的文件,那么我们可以使用下面的方法进行控制即可 1.创建不可删除文件 Linux:/qinys/oliver # touch test.sh ...
- V-rep学习笔记:Geometric Constraint Solver(几何约束求解)
The geometric constraint solver is slower and less precise at solving kinematic problems, but might ...
- Weblogic部署gbk编码的项目乱码
问题描述: weblogic默认部署的项目编码utf-8,由于项目特殊编码gbk导致打开项目中文全是乱码! 心哇凉哇凉.... 问题解决: 01.调休jvm参数 xxx_domains/bin/set ...
- Ubuntu18.04和OpenWrt 18.06.0 下使用aria2和BaiduExport处理百度盘下载
Ubuntu下没有可用的百度盘客户端, 下载大文件如果通过浏览器就会特别不可靠. 可以使用Chrome插件 BaiduExport 得到下载链接和参数后, 通过aria2进行下载. Aria2安装 直 ...
- \u Unicode和汉字转化
介绍 \uxxxx这种格式是Unicode写法,表示一个字符,其中xxxx表示一个16进制数字,范围所0-65535. Unicode十六进制数只能包含数字0-9.大写字母A-F或者小写字母A-F.需 ...
- 修改谷歌云google cloud engine VM root账户的密码和允许远程ssh登录
Figured it out. The VM's in cloud engine don't come with a root password setup by default so you'l ...
- NSNotificationCenter实现原理
# 前言 Cocoa中使用NSNotification.NSNotificationCenter和KVO来实现观察者模式,实现对象间一对多的依赖关系. 本篇文章主要来讨论NSNotification和 ...
- 深度优化LNMP之PHP
PHP缓存加速介绍 1.操作码介绍及缓存原理 当客户端请求一个php程序时,服务器的PHP引擎会解析该PHP程序,并将其编译为特定的操作码文件(Operate Code,opcode)该文 ...