Best way to get application folder path

前端 未结 10 2311
無奈伤痛
無奈伤痛 2020-11-22 02:03

I see that there are some ways to get the application folder path:

  1. Application.StartupPath
  2. System.IO.Path.GetDirectoryName( System.
10条回答
  •  佛祖请我去吃肉
    2020-11-22 02:36

    Note that not all of these methods will return the same value. In some cases, they can return the same value, but be careful, their purposes are different:

    Application.StartupPath
    

    returns the StartupPath parameter (can be set when run the application)

    System.IO.Directory.GetCurrentDirectory()
    

    returns the current directory, which may or may not be the folder where the application is located. The same goes for Environment.CurrentDirectory. In case you are using this in a DLL file, it will return the path of where the process is running (this is especially true in ASP.NET).

提交回复
热议问题