網上查找了不少例子,大多數是流,我只貼出一種簡單的,至於複雜的流輸出,懶得寫,網上也不少例子瀏覽器
文件流是能夠下載服務器文件,可是不能下載隨便給的網絡地址文件,因此蛋痛的查找了不少例子,最後發現服務器
WebClient 的方法DownloadData,能夠讀取爲byte[] 這就給了很大方便,幾行代碼搞定網絡
示例以下app
/// <summary> /// 文件下載 /// </summary> /// <param name="s_fileName"></param> public void downloadfile(string url) { String fileName = url.Substring(url.LastIndexOf("/") + 1); WebClient wc = new WebClient(); byte[] byti= wc.DownloadData(url); //通知瀏覽器保存文件,其實也就是輸出到瀏覽器 Response.Clear(); Response.ContentType = "application/octet-stream"; Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName); Response.BinaryWrite(byti); Response.Flush(); Response.Close(); }