当前位置:网站首页>C # 7 methods to obtain the current path
C # 7 methods to obtain the current path
2022-07-28 14:31:00 【CDamogu】
Get the current path 7 Methods

Here's the catalog title
Code
// Get the full path of the module .
string path1 = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
// Get and set the current directory ( The directory from which the process starts ) The fully qualified directory of
string path2 = System.Environment.CurrentDirectory;
// Get the current working directory of the application
string path3 = System.IO.Directory.GetCurrentDirectory();
// Get the base directory of the program
string path4 = System.AppDomain.CurrentDomain.BaseDirectory;
// Gets and sets the name of the directory that includes the application
string path5 = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
// Get the path of the executable file that started the application
string path6 = System.Windows.Forms.Application.StartupPath;
// Get the path and file name of the executable file that started the application
string path7 = System.Windows.Forms.Application.ExecutablePath;
StringBuilder str=new StringBuilder();
str.AppendLine("System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName:" + path1);
str.AppendLine("System.Environment.CurrentDirectory:" + path2);
str.AppendLine("System.IO.Directory.GetCurrentDirectory():" + path3);
str.AppendLine("System.AppDomain.CurrentDomain.BaseDirectory:" + path4);
str.AppendLine("System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase:" + path5);
str.AppendLine("System.Windows.Forms.Application.StartupPath:" + path6);
str.AppendLine("System.Windows.Forms.Application.ExecutablePath:" + path7);
string allPath = str.ToString();
Output results
System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName:D:\work\prj\VP-VPlatform\XmlAndXsd\bin\Release\XmlAndXsd.vshost.exe
System.Environment.CurrentDirectory:D:\work\prj\VP-VPlatform\XmlAndXsd\bin\Release
System.IO.Directory.GetCurrentDirectory():D:\work\prj\VP-VPlatform\XmlAndXsd\bin\Release
System.AppDomain.CurrentDomain.BaseDirectory:D:\work\prj\VP-VPlatform\XmlAndXsd\bin\Release\
System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase:D:\work\prj\VP-VPlatform\XmlAndXsd\bin\Release\
System.Windows.Forms.Application.StartupPath:D:\work\prj\VP-VPlatform\XmlAndXsd\bin\Release
System.Windows.Forms.Application.ExecutablePath:D:\work\prj\VP-VPlatform\XmlAndXsd\bin\Release\XmlAndXsd.EXE
Instructions for usage
- Net Framework in System.IO.Directory.GetCurrentDirectory() Method is used to get the current working directory of the application . If you use this method to get the directory where the application is located , It should be noted :System.IO.Directory.GetCurrentDirectory() The directory path obtained by the method follows OpenFileDialog、SaveFileDialog And so on ( Switch working directory ). Every time you open the folder or use explorer to view the file , Will change the value obtained by this method .
- and System.Windows.Forms.Application.StartupPath or System.AppDomain.CurrentDomain.BaseDirectory You can get the directory where the application runs , It doesn't change with the folder you open . It is only related to the application running directory , Its value is equal to the root directory of the application startup . For example, you installed the program in C:\Program Files\ Program folder Under the position of , So he is System.Windows.Forms.Application.StartupPath Value .
边栏推荐
- RSA encrypts data with private key and decrypts data with public key (not a signature verification process)
- Career planning of Software Test Engineer
- Four ways to create thread pools
- MiniTest--小程序自动化测试框架
- 力扣解法汇总1331-数组序号转换
- MySQL development skills - View
- 2022 melting welding and thermal cutting examination questions and online simulation examination
- Niuke multi school link with level editor i- (linear DP)
- How did Dongguan Huawei cloud data center become a new model of green data center?
- Force deduction solution summary 1331 array sequence number conversion
猜你喜欢

复制excel行到指定行

Many "double first-class" universities have launched the research guarantee and prediction name!

Metersphere -- Open Source continuous testing platform

草料二维码--在线二维码生成器

爆肝整理JVM十大模块知识点总结,不信你还不懂

Forage QR code -- online QR code generator

HCIP第十二天

Daily question - Scholarship

手机滚动截屏软件推荐

Development and definition of software testing
随机推荐
软件测试工程师的职业规划
数据库优化 理解这些就够了
IP black and white list
C# 读取ini文件、键值对操作
Leetcode 0143. rearrange linked list
如何只降3D相机不降UI相机的分辨率
Target detection: speed and accuracy comparison (fater r-cnn, r-fcn, SSD, FPN, retinanet and yolov3)
围绕新市民金融聚焦差异化产品设计、智能技术提效及素养教育
卡方分布和伽马函数(Chi-Square Distribution)
UFIDA BiP CRM new product launch enables large and medium-sized enterprises to grow their marketing
Multi level cache scheme
Leetcode 0142. circular linked list II
Niuke multi school link with level editor i- (linear DP)
Introduction to database system (5th Edition) supplementary exercises - Chapter 1 Introduction
Metersphere -- Open Source continuous testing platform
树莓派基础 | 总结记录树莓派学习过程中的一些操作
【七夕】七夕孤寡小青蛙究极版?七夕节最终章!
多所“双一流”大学,保研预报名启动!
如何有效进行回顾会议(上)?
OKR and grad