日期:2014-05-18 浏览次数:21047 次
private Stream GetStream(string strLink) { HttpWebRequest request = null; try { request = (HttpWebRequest)WebRequest.Create(strLink); request.UserAgent = "Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1;.NET CLR 2.0.50727)"; return request.GetResponse().GetResponseStream(); } catch { request.Abort(); return null; } } public bool SaveImage(string strLink,string strFolder,string strNewName,bool unique) { try { string strTmp = string.Empty; readstream = GetStream(strLink); if (readstream == null) { throw new Exception("获取图片错误"); } if (unique) { filestream = new FileStream(GetPath(strLink,strFolder,strNewName), FileMode.CreateNew, FileAccess.Write); } else { filestream = new FileStream(GetPath(strLink, strFolder, strNewName), FileMode.Create, FileAccess.Write); } do { length = readstream.Read(buffer, 0, buffer.Length); if (length == 0) { break; } filestream.Write(buffer, 0, length); } while (length > 0); return true; } catch { return false; } finally { Close(); } } //流都是stream类型 我写ftp的时候用到的,,,具体的你自己改! close这个函数的命令就是关闭这些流!!