/// <summary>
/// 网页下载文件
/// </summary>
/// <param name="DownloadPath">目标地址</param>
/// <param name="FullFilePath">原地址</param>
/// <param name="FileName">文件名</param>
/// <returns></returns>
public static bool DownLoadSoft(string DownloadPath, string FullFilePath, string FileName)
{
bool flag = false;
try
{
if (!Directory.Exists(DownloadPath))
{
Directory.CreateDirectory(DownloadPath);
}
using (FileStream fs = new FileStream(DownloadPath + "/" + FileName, FileMode.Create))
{
//创建请求
WebRequest request = WebRequest.Create(FullFilePath + FileName);
//接收响应
WebResponse response = request.GetResponse();
//输出流
Stream responseStream = response.GetResponseStream();
byte[] bufferBytes = new byte[10000];//缓冲字节数组
int bytesRead = -1;
while ((bytesRead = responseStream.Read(bufferBytes, 0, bufferBytes.Length)) > 0)
{
fs.Write(bufferBytes, 0, bytesRead);
}
if (fs.Length > 0)
{
flag = true;
}
//关闭写入
fs.Flush();
fs.Close();
}
}
catch (Exception exp)
{
//返回错误消息
}
return flag;
}