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

c#
2015-07-09 0 892
C# 判断远程文件是否存在
#region 判断远程文件是否存在  
       /// <summary>  
       /// 判断远程文件是否存在  
       /// </summary>  
       /// <param name="fileUrl"></param>  
       /// <returns></returns>  
       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 

遇见资源网 c# C# 判断远程文件是否存在 http://www.ox520.com/12929.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务