好记性不如烂笔头。

ASP.NET 判断远程文件是否存在

//判断远程文件是否存在
        private bool RemoteFileExists(string fileUrl)
        {
            bool result = false;//判断结果

            WebResponse response = null;
            try
            {
                WebRequest req = WebRequest.Create(fileUrl);

                response = req.GetResponse();

                result = response == null ? false : true;

            }
            catch (Exception ex)
            {
                result = false;
            }
            finally
            {
                if (response != null)
                {
                    response.Close();
                }
            }

            return result;
        }