C # 7 ways to get the current path

Source: Internet
Author: User

Original link: http://blog.csdn.net/liudong8510/article/details/17264297 (written very practical, very detailed)

Gets the full path of the module. String path1 = System.Diagnostics.Process.GetCurrentProcess ().  
Mainmodule.filename;  
Gets and sets the fully qualified directory string path2 = System.Environment.CurrentDirectory for the current directory (the directory from which the process starts);  
Gets the current working directory of the application string path3 = System.IO.Directory.GetCurrentDirectory ();  
Gets the base directory of the program string path4 = System.AppDomain.CurrentDomain.BaseDirectory;  
Gets and sets the name of the directory that contains the application string path5 = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;  
Gets the path to the executable file that started the application string path6 = System.Windows.Forms.Application.StartupPath;  
  
Gets the path and filename 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 result * 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.For Ms. Application.executablepath:d:\work\prj\vp-vplatform\xmlandxsd\bin\rElease\xmlandxsd.exe *  
 


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.