C # Ways to get Project program paths

Source: Internet
Author: User
1.asp.net for WebForm
"Request.physicalapplicationpath Gets the physical path of the virtual directory where the site resides, and finally contains" \ ";

2.c# for WinForm
A: "Application.startuppath": Gets the path of the directory where the current application resides, and finally does not contain "\";
B: "Application.executablepath": Gets the path of the current application file, including the name of the file;
C: "AppDomain.CurrentDomain.BaseDirectory": Gets the path of the directory where the current application resides, and finally contains "\";
D: "System.Threading.Thread.GetDomain (). BaseDirectory ": Gets the path to the directory where the current application resides, and finally contains" \ ";
E: "Environment.currentdirectory": Gets the path of the current application, and finally does not contain "\";
F: "System.IO.Directory.GetCurrentDirectory": Gets the path of the current application and does not include "\" at the end;

3.c# Windows Service
Use "AppDomain.CurrentDomain.BaseDirectory" or "System.Threading.Thread.GetDomain ()". BaseDirectory ";
Using "Environment.currentdirectory" and "System.IO.Directory.GetCurrentDirectory" will get the path of "system32" directory;
If you want to use "Application.startuppath" or "Application.executablepath", you need to manually add a reference to "System.Windows.Forms.dll", and at the beginning of the program use the "using System.Windows.Forms "declares the reference;

4. Get the directory of the system installation in the Uninstaller
System.Reflection.Assembly Curpath = System.Reflection.Assembly.GetExecutingAssembly ();
String path=curpath.location;//get the path to the Installer class Setuplibrary file, get the directory where the file path is located, get the directory of the Setup program

http://blog.163.com/dykj_dxj/blog/static/254925252010830113424205/
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.