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#: 获取当前路径的更多相关文章

  1. [No00006F]总结C#获取当前路径的各种方法

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  2. C#获取当前路径的7种方法

    总结C#获取当前路径的7种方法 C#获取当前路径的方法如下: 1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName ...

  3. 【转】C#(ASP.Net)获取当前路径的方法集合

    转自:http://www.gaobo.info/read.php/660.htm //获取当前进程的完整路径,包含文件名(进程名). string str = this.GetType().Asse ...

  4. C\C++ 获取当前路径

    C\C++ 获取当前路径   获取当前工作目录是使用函数:getcwd.cwd指的是“current working directory”,这样就好记忆了. 函数说明: 函数原型:char* getc ...

  5. [转]Java获取当前路径

    1.利用System.getProperty()函数获取当前路径:System.out.println(System.getProperty("user.dir"));//user ...

  6. C#获取当前路径的方法

    C#获取当前路径的方法如下: 1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName -获取模块的完整路径. 2. ...

  7. 【转】java获取当前路径的几种方法

    1.利用System.getProperty()函数获取当前路径: System.out.println(System.getProperty("user.dir"));//use ...

  8. C#获取当前路径,获取当前路径的上一层路径

    C#获取当前路径的方法如下: (1)string path1 = System.Environment.CurrentDirectory; //C:\...\bin\Debug -获取和设置当前工作目 ...

  9. Java获取当前路径

    1.利用System.getProperty()函数获取当前路径:System.out.println(System.getProperty("user.dir"));//user ...

  10. C#获取当前路径的几种方法

    C#获取当前路径的方法如下: 1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName -获取模块的完整路径. 2. ...

随机推荐

  1. ADO.NET实体数据模型使用探索1

    今天研究了下ADO.NET实体数据模型,想写个关于两张有外键关系的增改删查,以此来稍增加点难度. 编程环境:vs2010+sql2005 1.在SQL2005下建立三张表:学生信息表Student(S ...

  2. php apc

    APC,全称是Alternative PHP Cache,官方翻译叫”可选PHP缓存”.它为我们提供了缓存和优化PHP的中间代码的框架. APC的缓存分两部分:系统缓存和用户数据缓存. 系统缓存 它是 ...

  3. nginx https

    默认情况下ssl模块并未被安装,如果要使用该模块则需要在编译时指定–with-http_ssl_module参数,安装模块依赖于OpenSSL库和一些引用文件,通常这些文件并不在同一个软件包中.通常这 ...

  4. CSS3新添加的选择器

    ---条件选择器:--- .ccc[cusid*= value] { backgroud-color:#0094ff; } //表示使用了class="ccc"元素自定义属性cus ...

  5. Express创建并运行node项目(Jade和EJS模版引擎)

    1.创建Node项目 [Jade模板] > express nodeJade express创建项目若不显示指定模板,默认使用Jade,以下写法都可以: express -jade nodeJa ...

  6. Bone Collector

    if(j>=w[i]) dp[i][j] = max(dp[i-1][j-w[i]]+v[i], dp[i-1][j]); else dp[i][j]=dp[i-1][j]; i 1 2 3 4 ...

  7. 用Dictionary代替if

    public Dictionary<string, System.Drawing.RotateFlipType> dicRFT = new Dictionary<string, Sy ...

  8. <dependency>spring-webmvc</dependency>

    Spring 4.2.0.RELEASE版本: <dependency> <groupId>org.springframework</groupId> <ar ...

  9. 通过css3实现开关选择按钮

      通过css属性实现如图所示按钮 要点:通过checkbox选中与否的状态与兄弟选择器实现相关功能 1.设置开关大小并设置定位方式为relative .swift-btn {     positio ...

  10. php数组遍历

    <?php $arr = array('a','b','c','d','e','f'); //for语句只能遍历索引数组 for($i = 0; $i < 6; $i++){ echo $ ...