c# 獲得當(dāng)前絕對(duì)路徑的方法(超簡(jiǎn)單)
廢話不多說(shuō),直接上代碼
/// <summary>
/// 獲得當(dāng)前絕對(duì)路徑
/// </summary>
/// <param name="strPath">指定的路徑</param>
/// <returns>絕對(duì)路徑</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# 獲得當(dāng)前絕對(duì)路徑的方法(超簡(jiǎn)單)就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
c# Selenium爬取數(shù)據(jù)時(shí)防止webdriver封爬蟲(chóng)的方法
這篇文章主要介紹了c# Selenium爬取數(shù)據(jù)時(shí)防止webdriver封爬蟲(chóng)的方法,幫助大家更好的理解和使用c#,感興趣的朋友可以了解下2021-01-01
一文詳解C#中重寫(xiě)(override)及覆蓋(new)的區(qū)別
這篇文章主要為大家詳細(xì)介紹了C#中重寫(xiě)(override)及覆蓋(new)這兩個(gè)關(guān)鍵詞的區(qū)別,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解一下2023-03-03
C#中System.Array.CopyTo() 和 System.Array.Clon()&nbs
System.Array.CopyTo()和System.Array.Clone()是用于數(shù)組復(fù)制的兩種不同方法,本文就來(lái)介紹C,#中System.Array.CopyTo() 和 System.Array.Clon() 的區(qū)別,具有一定的參考價(jià)值,感興趣的可以了解一下2024-04-04
如何在C# 中查找或結(jié)束程序域中的主、子進(jìn)程
這篇文章主要介紹了如何在C# 中查找或結(jié)束程序域中的主、子進(jìn)程,幫助大家更好的理解和使用c#編程語(yǔ)言,感興趣的朋友可以了解下2020-11-11
通過(guò)C#編寫(xiě)一個(gè)簡(jiǎn)易的Windows截屏增強(qiáng)工具
在使用?Windows?系統(tǒng)的截屏快捷鍵?PrintScreen?截屏?xí)r,如果需要把截屏保存到文件,需要先粘貼到畫(huà)圖工具然后另存為文件。所以本文用C#編寫(xiě)了一個(gè)簡(jiǎn)易的Windows截屏增強(qiáng)工具,需要的可以參考一下2022-05-05
WPF實(shí)現(xiàn)手風(fēng)琴式輪播圖切換效果
這篇文章主要為大家詳細(xì)介紹了WPF實(shí)現(xiàn)手風(fēng)琴式輪播圖切換效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-09-09

