A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 韩继新 中级黑马   /  2013-9-16 16:36  /  1101 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

//判断服务器上指定路径文件是否存在,如果存在返回false,反之返回true
        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;
        }
        /// <summary>
        /// 从服务器下载图片,
        /// </summary>
        /// <param name="Url">Url地址</param>
        /// <param name="Path">保存路径</param>
        public void DownImage(string Url, string Path)
        {
            System.Net.WebClient web = new System.Net.WebClient();
            //如果保存路径已经存在同名文件则删除保存路径下的文件
            if (File.Exists(Path))
            {
                File.Delete(Path);
            }
           //下载
            web.DownloadFile(Url, Path);
        }

评分

参与人数 1技术分 +1 收起 理由
曹伟 + 1

查看全部评分

1 个回复

正序浏览
值得学习ing!
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马