/// <summary>
/// 下载附件
/// </summary>
/// <param name="strUrl"></param>
/// <param name="strFileName"></param>
public void DownloadPicture(string strUrl, string strFileName)
{
try
{
string strPath = string.Empty;
string strSavePath = string.Empty;
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(strUrl);
req.Method = "GET";
using (WebResponse wr = req.GetResponse())
{
HttpWebResponse myResponse = (HttpWebResponse)req.GetResponse();
strPath = myResponse.ResponseUri.ToString();
WebClient mywebclient = new WebClient();
//绝对路径
string strDownLoadPath = ConfigurationManager.AppSettings["RecordPath"];
strSavePath = strDownLoadPath + "\\" + strFileName;
if (!Directory.Exists(strDownLoadPath))
{
//自动生成文件夹
Directory.CreateDirectory(strDownLoadPath);
}
mywebclient.DownloadFile(strPath, strSavePath);
}
}
catch (Exception ex)
{
TraceLogHelper.Write(ex.Message);
}
}
通过网页路径下载文件
最新推荐文章于 2024-04-23 22:35:38 发布