开源是程序员的基本美德
/// <summary> /// 网络文件是否存在 /// </summary> /// <param name="url">网络路径</param> /// <returns></returns> private static bool NetFileExist(string url) { try { //创建根据网络地址的请求对象 System.Net.HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url)); httpWebRequest.Method = "HEAD"; httpWebRequest.Timeout = 1000; //返回响应状态是否是成功比较的布尔值 return ((HttpWebResponse)httpWebRequest.GetResponse()).StatusCode == HttpStatusCode.OK; } catch { return false; } }
留下您的脚步
最近评论