This article summarizes various methods for obtaining the current path in .NET (including ASP.NET/WinForm, etc.), which has certain reference value. Let’s take a look at it with the editor.
//Get the current path The full path of the process, including the file name (process name).
string str = this.GetType().Assembly.Location; result: X:\xxx\xxx\xxx.exe (.exe文件所在的目录+.exe文件名)
//Get the new Process component and associate it with the full path of the main module of the currently active process, including the file name (process name).
string str = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName; result: X:\xxx\xxx\xxx.exe (.exe文件所在的目录+.exe文件名)
//Gets and sets the fully qualified path of the current directory (that is, the directory from which the process was started).
string str = System.Environment.CurrentDirectory; result: X:\xxx\xxx (.exe文件所在的目录)
//Get the base directory of the current application domain of the current Thread, which is used by the assembly conflict resolver to detect the assembly.
string str = System.AppDomain.CurrentDomain.BaseDirectory; result: X:\xxx\xxx\ (.exe文件所在的目录+"\")
//Get and set the name of the directory containing the application.
string str = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase; result: X:\xxx\xxx\ (.exe文件所在的目录+"\")
//Get the path to the executable file that started the application, excluding the name of the executable file.
string str = System.Windows.Forms.Application.StartupPath; result: X:\xxx\xxx (.exe文件所在的目录)
//Get the path to the executable file that started the application, including the name of the executable file.
string str = System.Windows.Forms.Application.ExecutablePath; result: X:\xxx\xxx\xxx.exe (.exe文件所在的目录+.exe文件名)
//Get the current working directory of the application (unreliable).
string str = System.IO.Directory.GetCurrentDirectory(); result: X:\xxx\xxx (.exe文件所在的目录)
//Get the full path of the current process, including the file name (process name).
string str = this.GetType().Assembly.Location;result: X:\xxx\xxx\xxx.exe (.exe文件所在的目录+.exe文件名)
//Get the new Process component and associate it with the full path of the main module of the currently active process, including the file name (process name).
string str = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;result: X:\xxx\xxx\xxx.exe (.exe文件所在的目录+.exe文件名)
//Gets and sets the fully qualified path of the current directory (i.e. the directory from which the process was started).
string str = System.Environment.CurrentDirectory;result: X:\xxx\xxx (.exe文件所在的目录)
//Get the base directory of the current application domain of the current Thread, which is used by the assembly conflict resolver to detect the assembly.
string str = System.AppDomain.CurrentDomain.BaseDirectory;result: X:\xxx\xxx\ (.exe文件所在的目录+"\")
//Gets and sets the name of the directory containing the application.
string str = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;result: X:\xxx\xxx\ (.exe文件所在的目录+"\")
//Get the path to the executable file that started the application, excluding the name of the executable file.
string str = System.Windows.Forms.Application.StartupPath;result: X:\xxx\xxx (.exe文件所在的目录)
//Get the path to the executable file that started the application, including the name of the executable file.
string str = System.Windows.Forms.Application.ExecutablePath;result: X:\xxx\xxx\xxx.exe (.exe文件所在的目录+.exe文件名)
//Get the current working directory of the application (unreliable).
string str = System.IO.Directory.GetCurrentDirectory();result: X:\xxx\xxx (.exe文件所在的目录)
Three codes for obtaining the current path in .NET
//Web Programming
HttpContext.Current.Server.MapPath("FileName") System.Web.HttpContext.Current.Request.Path
//Windows Programming
System.Environment.CurrentDirectory
//Mobile Programming
Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
【Related Recommendations】
1. Special Recommendations:"php programmer tools "Box" V0.1 version download
3. Li Yanhui ASP basic video tutorial
The above is the detailed content of Share N kinds of .NET examples of obtaining the current path. For more information, please follow other related articles on the PHP Chinese website!

C# and .NET are suitable for web, desktop and mobile development. 1) In web development, ASP.NETCore supports cross-platform development. 2) Desktop development uses WPF and WinForms, which are suitable for different needs. 3) Mobile development realizes cross-platform applications through Xamarin.

The C#.NET ecosystem provides rich frameworks and libraries to help developers build applications efficiently. 1.ASP.NETCore is used to build high-performance web applications, 2.EntityFrameworkCore is used for database operations. By understanding the use and best practices of these tools, developers can improve the quality and performance of their applications.

How to deploy a C# .NET app to Azure or AWS? The answer is to use AzureAppService and AWSElasticBeanstalk. 1. On Azure, automate deployment using AzureAppService and AzurePipelines. 2. On AWS, use Amazon ElasticBeanstalk and AWSLambda to implement deployment and serverless compute.

The combination of C# and .NET provides developers with a powerful programming environment. 1) C# supports polymorphism and asynchronous programming, 2) .NET provides cross-platform capabilities and concurrent processing mechanisms, which makes them widely used in desktop, web and mobile application development.

.NETFramework is a software framework, and C# is a programming language. 1..NETFramework provides libraries and services, supporting desktop, web and mobile application development. 2.C# is designed for .NETFramework and supports modern programming functions. 3..NETFramework manages code execution through CLR, and the C# code is compiled into IL and runs by CLR. 4. Use .NETFramework to quickly develop applications, and C# provides advanced functions such as LINQ. 5. Common errors include type conversion and asynchronous programming deadlocks. VisualStudio tools are required for debugging.

C# is a modern, object-oriented programming language developed by Microsoft, and .NET is a development framework provided by Microsoft. C# combines the performance of C and the simplicity of Java, and is suitable for building various applications. The .NET framework supports multiple languages, provides garbage collection mechanisms, and simplifies memory management.

C# and .NET runtime work closely together to empower developers to efficient, powerful and cross-platform development capabilities. 1) C# is a type-safe and object-oriented programming language designed to integrate seamlessly with the .NET framework. 2) The .NET runtime manages the execution of C# code, provides garbage collection, type safety and other services, and ensures efficient and cross-platform operation.

To start C#.NET development, you need to: 1. Understand the basic knowledge of C# and the core concepts of the .NET framework; 2. Master the basic concepts of variables, data types, control structures, functions and classes; 3. Learn advanced features of C#, such as LINQ and asynchronous programming; 4. Be familiar with debugging techniques and performance optimization methods for common errors. With these steps, you can gradually penetrate the world of C#.NET and write efficient applications.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver CS6
Visual web development tools
