1.asp.net webform
1.1 Use “Request.PhysicalApplicationPath to get the physical path of the virtual directory where the site is located, and finally include “\”;
2. In c# winform
2.1 “Application.StartupPath”: Get the path of the directory where the current application is located, excluding “\” at the end;
2.2 “Application.ExecutablePath”: Get the path of the current application file, including the name of the file;
2.3 “AppDomain.CurrentDomain.BaseDirectory”: Get the path of the directory where the current application is located, including “\” at the end;
2.4 “System.Threading.Thread.GetDomain().BaseDirectory”: Get the path of the directory where the current application is located, including “\” at the end;
2.5 “Environment.CurrentDirectory”: Get the path of the current application, without “\” at the end;
2.6 “System.IO.Directory.GetCurrentDirectory”: Get the path of the current application, excluding “\” at the end;
3. c# windows service service
3.1 “AppDomain.CurrentDomain.BaseDirectory” or “System.Threading.Thread.GetDomain().BaseDirectory”;
3.2 “Environment.CurrentDirectory” and “System.IO.Directory.GetCurrentDirectory” will get the path to the “system32” directory;
Note : If you want to use “Application.StartupPath” or “Application.ExecutablePath”
You need to manually add a reference to “System.Windows.Forms.dll” and declare the reference with “using System.Windows.Forms” at the beginning of the program;
4. Obtain the system installation directory in the uninstaller:
4.1System.Reflection.Assembly curPath = System.Reflection.Assembly.GetExecutingAssembly();
string path=curPath.Location;//Get the path of the installer class SetupLibrary file, get the directory where the file path is located to get the directory of the installer;
4.2System.Diagnostics.StackFrame f = new System.Diagnostics.StackFrame(1);
MethodBase mb = f.GetMethod();
System.Web.HttpContext.Current.Response.Write(mb.DeclaringType.ToString()); Get the information of the calling class, you can know the situation of the subclass from the parent class
Read More:
- File class details (get the file name, size, path, create, etc.)
- Android: How to get the size of font you set (Example Code)
- Docker: How to build a rabbitmq image cluster
- Android: How to Add Background Music for Activity with Service
- Electron: How to Use BrowserWindow to Create a Window
- Canvas: How to Implement Video Screenshot Function
- How to Use Printf in HAL Library
- torch.max Example (How to Use)
- Windows Core Audio APIs: How to Progress Loopback Recording and Generate WAV File
- Python: How to Create List by Comprehension (Example Codes)
- Jquery use queue to implement Ajax request queue Simple Example
- Opentelemetry + Jaeger Python Version Cross Service Call Example
- MultipartFile Upload an Image Example
- Adobe ColdFusion Files Read Vulnerability (CVE-2010-2861)
- Hutool Excel Import & Export Example
- Echarts-for-React Example (Install, Import and Effect)
- Flutter & Dart Enumeration Example
- Websocket Front-end Call Example
- Flutter & Dart Regular Expression Examples
- Open CASCADE Technology 7.7.0 released