C # relative path

Source: Internet
Author: User

I. C # WinForm

1.image

pictureBox1.Image = Image.FromFile (Application.startuppath + @ "\1.jpg");

Application.startuppath is generally found under the Debug folder

pictureBox1.Image = Image.FromFile (string path);

string [email protected] "photo\empty.png";

AppDomain.CurrentDomain.BaseDirectory Program Run Directory

Reproduced

1. Root directory

.//or give the file name directly, the path to the root directory.

For example: Path = "Test.xml" and Path = ".//test.xml" is a meaning.

2, the root directory of the parent directory, in C # is specified in the Bin folder inside

.. Top level two of the application's root directory

3. Specify the level three directory above the root directory, which is the same directory as the bin in C #

.. //.. Test.xml This means that in the root directory of the level three directory of the Gs.mdb file

If in this directory you want to specify a file in the specified folder, you should: //.. Xml//test.xml meaning the Test.xml file below the XML file in this directory.

4. Specify the top level four directory to the root directory, as follows:

.. //.. //.. This assigns the fourth level directory to the root directory.

.. //.. //.. Xml//test.xml This path is assigned to the Dir in this directory Gs.mdb this folder.

5. Relative path of a file

.. Draw//xml//test.xml such as: For example, there are now several folder XML, Draw, tool, and the application is now in the XML folder, Then this path means specifying the file path of the Test.xml in the draw bin of the two level directory on the XML file.

Original: http://blog.sina.com.cn/s/blog_449f737a0100hj07.html

1. Gets and sets the fully qualified path to the current directory.

string str = System.Environment.CurrentDirectory;

Result:c:/xxx/xxx

2. Gets the path to the executable file that launched the application, not including the name of the executable file.

String str = System. Windows. Forms.Application.StartupPath;

Result:c:/xxx/xxx

3. Gets the full path of the new process component and associates it with the main module associated with the currently active process, including the file name.

String str = System.Diagnostics.Process.GetCurrentProcess (). Mainmodule.filename;

Result:c:/xxx/xxx/xxx.exe

4. Gets the base directory of the current application domain for Thread, which is used by the Assembly resolver to probe assemblies.

string str = System.AppDomain.CurrentDomain.BaseDirectory;

result:c:/xxx/xxx/

5. Get the current working directory of the application.

String str = System.IO.Directory.GetCurrentDirectory ();

Result:c:/xxx/xxx

6. Gets and sets the name of the directory that contains the application.

string str = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;

result:c:/xxx/xxx/

7. Gets the full path of the current process, including the file name.

String str = this. GetType (). Assembly.location;

Result:c:/xxx/xxx/xxx.exe

8. Get the path to the executable file that launched the application, including the name of the executable file.

String str = System. Windows. Forms.Application.ExecutablePath;

Result:c:/xxx/xxx/xxx.exe

In addition, see Configuring Specific paths through XML files to achieve a reasonable location for planning configuration files, such as paths in configuration files in the Web.


String str1 =process.getcurrentprocess (). mainmodule.filename;//gets the file name of the EXE that is currently executing.
String str2=environment.currentdirectory;//gets and sets the fully qualified path to the current directory (that is, the directory from which the process starts).
Note by definition, if the process is started in the root directory of a local or network drive, the value of this property is the drive name followed by a trailing backslash (such as "c:/"). If the process is started in a subdirectory, the value of this property is the drive and subdirectory path (such as "c:/mysubdirectory") without trailing backslashes.
String Str3=directory.getcurrentdirectory ();//Gets the current working directory of the application.
String str4=appdomain.currentdomain.basedirectory;//gets the base directory that is used by the Assembly resolver to probe assemblies.
String str5=application.startuppath;//gets the path to the executable file that launched the application, not including the name of the executable file.
String str6=application.executablepath;//gets the path to the executable file that launched the application, including the name of the executable file.
String str7=appdomain.currentdomain.setupinformation.applicationbase;//Gets or sets the name of the directory that contains the application.

C # relative path

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.