[英]How to find absolute path using a relative path in c#
我有一個存儲在變量中的路徑
string partialPath = '\editors\tinymce'
我想獲得上述國際劍聯的完整路徑。 上面文件的實際路徑是“ D:\\ Backup \\ editors \\ tinymce”。 如何在C#中執行此操作。 謝謝
var dir = Directory.GetCurrentDirectory();
var output = Path.Combine(dir, partialPath);
這可能為您解決問題
string partialPath = "\editors\tinymce";
string fullPath = Path.GetFullPath(partialPath);
輸出:
D:\\ editors \\ tinymce
鑒於
這可能為您解決問題
string partialPath = "editors\tinymce";
fullPath = Path.GetFullPath(partialPath);
輸出:
D:\\ Backup \\ editors \\ tinymce
請嘗試以下代碼:
碼:
string partialPath = "\editors\tinymce";
var output = Server.MapPath(partialPath);
string str = HttpContext.Current.Server.MapPath(partialPath);
您可以在輸出var和str字符串上獲取路徑。
讓我們知道。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.