/// <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判断图片存在的并获取图片
最新推荐文章于 2022-10-26 10:18:57 发布