廢話不多說,直接上代碼
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
/// < summary > /// 獲得當前絕對路徑 /// </ summary > /// < param name = "strPath" >指定的路徑</ param > /// < returns >絕對路徑</ returns > public static string GetMapPath(string strPath) { if (strPath.ToLower().StartsWith("http://")) { return strPath; } if (HttpContext.Current != null) { string path = HttpContext.Current.Server.MapPath("~/" + strPath); return path; } else //非web程序引用 { strPath = strPath.Replace("/", "\\"); if (strPath.StartsWith("\\")) { strPath = strPath.Substring(strPath.IndexOf('\\', 1)).TrimStart('\\'); } return System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, strPath); } } |
以上這篇c# 獲得當前絕對路徑的方法(超簡單)就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持服務器之家。
原文鏈接:http://www.cnblogs.com/highest/p/8301376.html