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. Python中dict的特点、更新dict、遍历dict

    dict的第一个特点是查找速度快,无论dict有10个元素还是10万个元素,查找速度都一样.而list的查找速度随着元素增加而逐渐下降. 不过dict的查找速度快不是没有代价的,dict的缺点是占用内 ...

  2. C#窗体:关于DataGridView的数据源绑定字符串两个值得注意的问题

    无意间遇到的问题,然后就GOOGLE了下,搜到些资料,总结整理如下(注:是转载的) 1. LINQ的查询结果无法直接作为DataGridView的数据源 DataGridView的DataSource ...

  3. GetLogicalProcessorInformation(XP3才支持)和GetLogicalProcessorInformationEx(WIN7才支持)

    https://msdn.microsoft.com/en-us/library/windows/desktop/ms683194(v=vs.85).aspx 例子执行结果如下: https://ms ...

  4. 自己diy一个jquery分页插件

    js基础学习过程中,期间经历换工作的各种面试,很多面试官问过:有没有写过jquery插件?等类似问题. 就个人而言,关于jquery插件的文章确实看过不少,但是一直没有动手写一个,一是不想在目前学习j ...

  5. [LeetCode] Substring with Concatenation of All Words(good)

    You are given a string, S, and a list of words, L, that are all of the same length. Find all startin ...

  6. How to pass selected records from form to dilog in AX 2012

    static void main(Args args) { FormDataSource formDataSource; ; if(args.record().TableId == tablenum( ...

  7. A Guide to Creating a Quality Project Schedule

    Successful projects start with a good quality project schedule. Creating a schedule is one of the fi ...

  8. An unknown Subversion error occurred. (code = 155037)

    这是因为在svn更新时意外中断引起的. 我的解决办法:如果本地没有更改,只是单纯获取svn的项目,则另起一个文件夹,重新checkout: 如果是本地有更改,则复制到新的文件夹,重新update.

  9. JDK的安装!力求简单明了!

    作为一个java语言的开发人员,第一件事就是安装JDK,就像当兵的要有刀枪,学生要有书本纸笔一样!话不多说,配置如下: 1.下载一个JDK安装包,解压到任意目录,我解压的是:C:\Tools\Java ...

  10. SqlServer基础:约束

    为了减少输入错误和保证数据库数据的完整性,可以对字段设置约束,例如考试成绩,其范围应该为0-100.约束是为了保证数据的完整性而实现的一套机制,约束包括:主键约束.外键约束.Unique约束.Chec ...