您好,登錄后才能下訂單哦!
/// <summary> /// 保存遠(yuǎn)程文件到本地 /// </summary> /// <param name="url">遠(yuǎn)程文件URL</param> /// <param name="file">保存的本地路徑</param> /// <returns></returns> public bool DownloadFile(string url, string file) { try { (new System.Net.WebClient()).DownloadFile(url,file); return true; } catch { } return false; } public void Download(string strURL,string strName) { string strRootDir = "D:\\DownLoadRecode"; if (!Directory.Exists(strRootDir)) { Directory.CreateDirectory(strRootDir); } WebClient client = new WebClient(); string strFileName = string.Empty; string strFileDir = string.Empty; string strSavePath = string.Empty; string[] arrName = strName.Split('/'); if (arrName != null && arrName.Length > 1) { strFileDir = arrName[0]; strFileName = arrName[1]; strSavePath = strRootDir + "\\" + strFileDir; if (!Directory.Exists(strSavePath)) { Directory.CreateDirectory(strSavePath); } } else { strFileName = strName; strSavePath = strRootDir + "\\Temp"; if (!Directory.Exists(strSavePath)) { Directory.CreateDirectory(strSavePath); } } strSavePath += "\\" + strFileName; if (!File.Exists(strSavePath)) { client.DownloadFile(strURL, strSavePath); } FileInfo xFileInfo = new FileInfo(strSavePath); Response.Clear(); //清除緩沖區(qū)流中的所有內(nèi)容輸出 Response.ClearHeaders(); //清除緩沖區(qū)中的所有頭 Response.Buffer = false; //設(shè)置緩沖輸出為 false //設(shè)置輸出流的 HTTP MIME 類型為 application/octet-stream Response.ContentType = "audio/x-wav"; Response.Charset = "GB2312"; Response.ContentEncoding = Encoding.UTF8; //將 HTTP 頭添加到輸出流 Response.AppendHeader("Content-Disposition", "p_w_upload;filename=" + HttpUtility.UrlEncode(strFileName)); Response.AppendHeader("Content-Length", xFileInfo.Length.ToString()); //將指定的字符直接寫入HTTP內(nèi)容輸出流 Response.WriteFile(strSavePath); Response.Flush(); Response.End(); }
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。