.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. ...
随机推荐
- 【转】get a mysterious problem,when i use HttpWebRequest in unity c# script
in script,i use HttpWebRequest to get service from network.but it comes a mysterious problem. the so ...
- 实例讲述PHP面向对象的特性;;;php中const与define的使用区别
php中const与define的使用区别 1.const:类成员变量定义,一旦定义且不能改变其值. define:定义全局常量,在任何地方都可以访问.2.define:不能在类中定义,而const可 ...
- Delphi XE5 Android 程序退出功能
Uses FMX.Platform.Android; ... begin {退出程序} MainActivity.finish; end;
- Device ID
参考文章 一.CFUUID (Deprecated) 二.UDID (Deprecated) 三.NSUUID (ios6.0 and later) NSString *uuid = [[NSUUID ...
- nginx https
默认情况下ssl模块并未被安装,如果要使用该模块则需要在编译时指定–with-http_ssl_module参数,安装模块依赖于OpenSSL库和一些引用文件,通常这些文件并不在同一个软件包中.通常这 ...
- aspx后台页面添加服务器控件
System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(); System.IO.StringWriter st ...
- Apache Commons Codec 编码解码
Apache Commons Codec jar包官方下载地址 下载解压后把commons-codec-1.9.jar 放到lib中 关于SHA1算法的介绍可以参看Wiki:http://en.wik ...
- C语言:其他进制转换为十进制(方法二)
#include<stdio.h> #include<math.h> #include<string.h> #include<ctype.h> //其他 ...
- 概率dp入门
概率DP主要用于求解期望.概率等题目. 转移方程有时候比较灵活. 一般求概率是正推,求期望是逆推.通过题目可以体会到这点. poj2096:Collecting Bugs #include <i ...
- webconfig和appconfig中出现特殊字符如何处理
在配置文件出现特殊字符&的字符串(如:abce&efg),就会报错.错误如下: 如何处理呢? config文件的本质是xml,所以必须符合xml的规范我们需要这么处理: abce&am ...