![](/img/trans.png)
[英]Ubiquitous way to get the file system root of a .NET WEB application
[英]Ubiquitous way to get the root directory an application is running in via C#
我的應用程序要求我可以訪問文件系統。 無論代碼是在Web服務器還是控制台應用程序上運行,我如何獲得運行應用程序的根目錄。像C:\\ TheApplication ...
謝謝!
最簡單的可能是:
System.Reflection.Assembly.GetExecutingAssembly().Location
希望這可以幫助,
-Oisin
我剛剛測試了一種非常基本的方法,可以在asp.net和windows服務中運行。
var binariesPath = string.IsNullOrEmpty(AppDomain.CurrentDomain.RelativeSearchPath)
? AppDomain.CurrentDomain.BaseDirectory // Windows Service
: AppDomain.CurrentDomain.RelativeSearchPath; // Asp.net
更簡單:
string myPath = Application.ExecutablePath;
對於winforms應用程序,始終設置此項。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.