.NET: C#: 获取当前路径
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Xml;
using System.Configuration;
using System.Reflection;
using System.Windows.Forms;
using System.IO;
namespace ConsoleTest
{
public class Program
{
static void Main(string[] args)
{
;
Console.WriteLine(Assembly.GetExecutingAssembly().Location);
Console.WriteLine(a.GetType().Assembly.Location);
Console.WriteLine(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
Console.WriteLine(System.Environment.CurrentDirectory);
Console.WriteLine(System.AppDomain.CurrentDomain.BaseDirectory);
Console.WriteLine(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase);
Console.WriteLine(System.Windows.Forms.Application.StartupPath);
Console.WriteLine(System.Windows.Forms.Application.ExecutablePath);
Console.WriteLine(System.IO.Directory.GetCurrentDirectory());
Console.WriteLine();
string path = "d:asdfasdf.bmp";
Console.WriteLine(Path.GetFileName(path));
Console.WriteLine(Path.GetExtension(path));
path = @"C:\Users\Administrator\Desktop\Demo";
if (Directory.Exists(path))
Console.WriteLine("{0} Directory exists", path);
else
Console.WriteLine("{0} Directory does not exist", path);
if (File.Exists(path))
Console.WriteLine("{0} File exists", path);
else
Console.WriteLine("{0} File does not exist", path);
path = @"C:\Users\Administrator\Desktop\Demo\Book.XML";
if (Directory.Exists(path))
Console.WriteLine("{0} Directory exists", path);
else
Console.WriteLine("{0} Directory does not exist", path);
if (File.Exists(path))
Console.WriteLine("{0} File exists", path);
else
Console.WriteLine("{0} File does not exist", path);
Console.WriteLine();
Console.WriteLine(Path.GetDirectoryName(path));
Console.WriteLine(Path.GetExtension(path));
Console.WriteLine(Path.GetFileName(path));
Console.WriteLine(Path.GetFileNameWithoutExtension(path));
Console.WriteLine(Path.GetPathRoot(path));
Console.WriteLine(Environment.SystemDirectory);
}
}
}
result

we usually use codes as below to get current directory:
System.Environment.CurrentDirectory
System.Windows.Forms.Application.StartupPath(using System.Windows.Forms;)
System.IO.Directory.GetCurrentDirectory() (using System.IO;)
I prefer: Enviroment.CurrentDirectory
.NET: C#: 获取当前路径的更多相关文章
- [No00006F]总结C#获取当前路径的各种方法
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- C#获取当前路径的7种方法
总结C#获取当前路径的7种方法 C#获取当前路径的方法如下: 1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName ...
- 【转】C#(ASP.Net)获取当前路径的方法集合
转自:http://www.gaobo.info/read.php/660.htm //获取当前进程的完整路径,包含文件名(进程名). string str = this.GetType().Asse ...
- C\C++ 获取当前路径
C\C++ 获取当前路径 获取当前工作目录是使用函数:getcwd.cwd指的是“current working directory”,这样就好记忆了. 函数说明: 函数原型:char* getc ...
- [转]Java获取当前路径
1.利用System.getProperty()函数获取当前路径:System.out.println(System.getProperty("user.dir"));//user ...
- C#获取当前路径的方法
C#获取当前路径的方法如下: 1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName -获取模块的完整路径. 2. ...
- 【转】java获取当前路径的几种方法
1.利用System.getProperty()函数获取当前路径: System.out.println(System.getProperty("user.dir"));//use ...
- C#获取当前路径,获取当前路径的上一层路径
C#获取当前路径的方法如下: (1)string path1 = System.Environment.CurrentDirectory; //C:\...\bin\Debug -获取和设置当前工作目 ...
- Java获取当前路径
1.利用System.getProperty()函数获取当前路径:System.out.println(System.getProperty("user.dir"));//user ...
- C#获取当前路径的几种方法
C#获取当前路径的方法如下: 1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName -获取模块的完整路径. 2. ...
随机推荐
- 【No.2 Ionic】Android打包
项目做完之后 接下来就是打包操作了,接下来直接说Android 打包操作 生成签名证书 keytool -genkey -alias vincentguo -keyalg RSA -validity ...
- jquery 事件 多次绑定,多次触发,怎么清除历史绑定事件
Jquery在处理事件的时候有时候会遇到预想不到的结果 如下 <a id="link_foo">Foo</a> <script type=" ...
- sql 语句查询练习题
1. 查询Student表中的所有记录的Sname.Ssex和Class列. select sname,ssex,class from student 2. 查询教师所有的单位即不重复的Depart列 ...
- EF的表连接方法Include()
在EF中表连接常用的有Join()和Include(),两者都可以实现两张表的连接,但又有所不同. 例如有个唱片表Album(AlbumId,Name,CreateDate,GenreId),表中含外 ...
- docker kubernetes--
http://kubernetes.io/docs/getting-started-guides/docker/ https://hub.docker.com/r/solsson/hyperkube- ...
- ZooKeeper Recipes and Solutions 翻译
ZooKeeper 秘诀 与解决方案 A Guide to Creating Higher-level Constructs with ZooKeeper Out of the Box Applica ...
- 【Java 基础篇】【第八课】package包
学习Java以来,第一次感觉稍微有点不好理解的,下面说说吧. 存在意义: 包的存在就是为更好的组织结构 包的创建: 只要在程序的最前面加入 Package ******,就可以了,一般都喜欢写 com ...
- C++ 类成员函数作为参数
#include <iostream> using namespace std; typedef int int32_t; struct IMsgBody{ int body; }; st ...
- eclipse有时候会报错:Cannot change version of project facet Dynamic Web Module to 2.5。这个错误不会影响程序的运行,不过看着总是不舒服。这个问题现在可以解决啦。
把项目WEB-INF底下的web.xml文件头部的: <?xml version="1.0" encoding="UTF-8"?> < ...
- contentOffset,frame,bounds,contentSize,ContentInset
contentOffset, 在UIScrollview里面滚动条用的最多,比如网易新闻的滚动条,肯定会用到这个. 我认为:它是下一个要显示的图片的左上角.设置了这个左上角后,下一次滚动时,邮戳直接到 ...