C # get file path

Source: Internet
Author: User

WinForm Get file path

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. 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.

"Application.startuppath": Gets the path to the directory where the current application resides, and finally does not contain "\"; "Application.executablepath": Gets the path to the current application file, including the name of the file; " AppDomain.CurrentDomain.BaseDirectory ": Gets the path to the directory where the current application resides, and finally contains" \ ";" System.Threading.Thread.GetDomain (). BaseDirectory ": Gets the path to the directory where the current application resides, and finally contains" \ ";" Environment.currentdirectory ": Gets the path of the current application, and finally does not contain" \ ";" System.IO.Directory.GetCurrentDirectory ": Gets the path of the current application, and finally does not contain" \ ";

string[] files = System.IO.Directory.GetFiles (path)//returns the file name under the specified directory

String str = System.IO.Path.GetFileNameWithoutExtension (path);//Returns the file name of the specified path string that does not have an extension

1. Obtain the root of the console application method      Method 1, Environment.currentdirectory Gets or sets the fully qualified path of the current working directory       Method 2, AppDomain.CurrentDomain.BaseDirectory gets the base directory, which is used by the Assembly resolver to probe the assembly  2, get the Web application's root method       Method 1, HttpRuntime.AppDomainAppPath.ToString ();//Gets the physical drive path of the application directory that hosts the application in the current application domain. For App_Data      Method 2, Server.MapPath ("") or Server.MapPath ("~/");// Returns the physical file path relative to the specified virtual path on the Web server      Method 3, request.applicationpath;//gets the virtual application root of the ASP. NET application on the server  3, get the root directory method of WinForm application      1, Environment.CurrentDirectory.ToString ();// Gets or sets the fully qualified path to the current working directory      2, Application.StartupPath.ToString ();//Gets the path to the executable file that launched the application, Does not include the name of the executable file      3, directory.getcurrentdirectory ();//Gets the current working directory of the application      4, appdomain.currentdomain.basedirectory;//gets the base directory, which is used by the Assembly resolver to probe assemblies      5, appdomain.currentdomain.setupinformation.applicationbase;//Gets or sets the name of the directory that contains the application: The following two methods can get the execution file name      1, process.getcurrentprocess (). mainmodule.filename;//gets the file name of the EXE that is currently executing.      2, application.executablepath;//gets the path to the executable file that launched the application, including the name of the executable file

3. There are some ways to get paths in the System.IO.Path class, which can be obtained by relative paths in the console program or WinForm

The method to get the Web physical path is Server.mpapath ("~")

C # get file 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.