/// <summary>
/// 判斷本地、遠程圖片,取圖片
/// </summary>
/// <param name="RecPic">要判斷的圖片路徑</param>
/// <returns></returns>
public static string GetDefualCourseImgtUrl(string RecPic)
{
string resultPath = string.Empty;
string m_ImgPath = UploadPathHelper.GetUploadPath();
if (string.IsNullOrEmpty(RecPic) || (!IsExistRemoteImage(RecPic) && !File.Exists(PathHelper.ServerMapPath("~/"+m_ImgPath + RecPic))))
{
//獲取默認圖片的方法
resultPath = GetDefaultImageUrl();
}
else
{
if(IsExistRemoteImage(RecPic))
{
resultPath = RecPic;
}
else if(File.Exists(PathHelper.ServerMapPath("~/"+m_ImgPath + RecPic)))//<span style="font-family: Arial, Helvetica, sans-serif;">PathHelper.ServerMapPath自己封裝獲取絕對路徑的方法</span>
{
resultPath = m_ImgPath + RecPic;
}
else
{
//獲取默認圖片的方法
resultPath = GetDefaultImageUrl();
}
}
return resultPath;
}
/// <summary>
/// 遠程判斷圖片是否存在
/// </summary>
/// <param name="curl"></param>
/// <returns></returns>
private static bool IsExistRemoteImage(string curl)
{
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(curl));
ServicePointManager.Expect100Continue = false;
((HttpWebResponse)request.GetResponse()).Close();</span>
return true;
}
catch
{
return false;
}
}
Asp.net判斷圖片存在的並獲取圖片
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.