.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. ...
随机推荐
- nodejs 执行shell 命令
有需要从前端操作服务器执行shell命令的需求 建立一个process.js文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 var process = ...
- 【转】Problems with HTTPS, HttpWebRequest, and iOS?
We're using HttpWebRequest to hit HTTPS urls, on iOS. In Debug, local builds, etc. everything works ...
- jboss4.2.3建立oracle JMS应用
一.基本配置 1 增加oracle驱动文件,ojdbc6.jar,不能使用小于该版本的jdbc驱动,jboss-4.2.3.GA\server\default\lib 2 增加retrotransla ...
- ADS报错 Warning : L6301W:Could not find file C:\Program Files . Error : L6218 : Undefined symbol ......
ADS1.2编译时,出现找不到一个不存在目录下的目标文件(*.o) 编译一个COPY到硬盘上的一个工程,出现以下的fatal error message: Error: (Fatal)L6002: C ...
- 怎么清除file控件的文件路径
还记得上次做一个文件上传,后来测试告诉我说,如果我要是不选择文件了呢?该怎么办?我说:简单啊,做一个取消按钮不就完事了吗!然后我就想一个file空间做一个取消是多么简单的事,用js处理可是想怎么样就怎 ...
- Using Feedback as a Tool
As a project manager it is important to be able to give and receive feedback effectively. Feedback i ...
- 用代码调用Storyboard里面的viewController
今天在帮助群里的一个朋友弄pop事件,在他那边,当前的viewcontroller,不能pop出去. 初步估计,他的ViewController层级多,他自己没有理清. 因为pushViewContr ...
- 解决.Net设置只读、隐藏后后台获取不到值的问题
在前台页面上放了几个textbox,用 ReadOnly=true设置不可编辑,用visible="False"设置不可见 用jquery给textbox赋值后在后台页面获取不到t ...
- 我的工具箱之MySql Front 5.3
下载地址:http://pan.baidu.com/s/1i4sJpNB 这款软件用来连接MySql,作为前端使用. 它功能全面,方便快捷,如果说有缺点的话,sql窗口中不能执行选择的部分有遗憾. 2 ...
- http://blog.csdn.net/foreverling/article/details/51385128
http://blog.csdn.net/foreverling/article/details/51385128