C# 判斷遠程文件是否存在
#region 判斷遠程文件是否存在
///
/// 判斷遠程文件是否存在
///
///
///
public static bool RemoteFileExists(string fileUrl)
{
HttpWebRequest re = null;
HttpWebResponse res = null;
try
{
re = (HttpWebRequest)WebRequest.Create(fileUrl);
res = (HttpWebResponse)re.GetResponse();
if (res.ContentLength != 0)
{
//MessageBox.Show("文件存在");
return true;
}
}
catch (Exception)
{
//MessageBox.Show("無此文件");
return false;
}
finally
{
if (re != null)
{
re.Abort();//銷毀關閉連接
}
if (res != null)
{
res.Close();//銷毀關閉響應
}
}
return false;
}
#endregion