关键词搜索

源码搜索 ×
×

C# 判断远程文件是否存在

发布2015-06-17浏览5809次

详情内容

  1. #region 判断远程文件是否存在
  2. /// <summary>
  3. /// 判断远程文件是否存在
  4. /// </summary>
  5. /// <param name="fileUrl"></param>
  6. /// <returns></returns>
  7. public static bool RemoteFileExists(string fileUrl)
  8. {
  9. HttpWebRequest re = null;
  10. HttpWebResponse res = null;
  11. try
  12. {
  13. re = (HttpWebRequest)WebRequest.Create(fileUrl);
  14. res = (HttpWebResponse)re.GetResponse();
  15. if (res.ContentLength != 0)
  16. {
  17. //MessageBox.Show("文件存在");
  18. return true;
  19. }
  20. }
  21. catch (Exception)
  22. {
  23. //MessageBox.Show("无此文件");
  24. return false;
  25. }
  26. finally
  27. {
  28. if (re != null)
  29. {
  30. re.Abort();//销毁关闭连接
  31. }
  32. if (res != null)
  33. {
  34. res.Close();//销毁关闭响应
  35. }
  36. }
  37. return false;
  38. }
  39. #endregion

相关技术文章

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载