asp.net已流的方式下载文件

string filePath = context.Server.MapPath("~/" + uploadFolder+"/"+file_name);//路径
System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath);
if (fileInfo.Exists == true)
{
//以字符流的形式下载文件
FileStream fs = new FileStream(filePath, FileMode.Open);
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
Response.ContentType = "application/octet-stream";
//通知浏览器下载文件而不是打开
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(file_name, System.Text.Encoding.UTF8));
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
}
else
{
//context.Response.Write("the download files is not exists");
}

时间: 2024-07-28 21:59:44

asp.net已流的方式下载文件的相关文章

文件流的方式下载文件

//流方式下载 protected void Button4_Click(object sender, EventArgs e) { string fileName = "aaa.zip";//客户端保存的文件名 string filePath = Server.MapPath("DownLoad/aaa.zip");//路径 //以字符流的形式下载文件 FileStream fs = new FileStream(filePath, FileMode.Open);

以流的方式下载文件

封装的axios下载 // 下载数据 export const downloadFile = (id) => { return axios.request({ url: '/file-manage/file/download/' + id, method: 'get', responseType: 'blob' }) } 传入下载的文件名,对应的文件id来下载流格式的文件 // 下载文件 downloadFile (filename, id) { downloadFile(id).then(re

C# Http方式下载文件到本地

下文代码是从网络(http://www.cnblogs.com/hayden/archive/2012/04/26/2472815.html)得来,亲测好用.我中修改了下格式和注释,版权属于原作者. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Net; namespace ConsoleTest { class

返回流的形式下载文件

//下载文件 private void Down(HttpContext context) { string filePath = context.Request["url"]; if (!string.IsNullOrEmpty(filePath)) { string customFileName = DateTime.Now.ToString("yyyyMMddHHmmss");//客户端保存的文件名 using (FileStream fileStream =

java通过http方式下载文件

package com.qiyi; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.URL; import java.net.URLConnection; import java.util.List; import java.util.Map; import java.io

asp.net中用FileStream类实现下载文件功能,自定义下载路径,像IE下载一样

方法一: //这个值可以从配置文件读取,或者放个textbox让用户填 string path = "你的路径";FileStream outputStream = new FileStream(path , FileMode.Create); 方法二: 直接用Response内置对象把文件以流的形式传到前端,浏览器自动就会识别下载了

重载Python FTP_TLS 实现Implicit FTP Over TLS方式下载文件

对于Python2.7来说,内置的FTP_TLS类并不支持Implicit FTP Over TLS加密方式的FTP Server操作,为支持Implicit FTP Over TLS加密方式,必须重载内置的FTP_TLS类,具体代码如下: import ftplib class FTP_TLS(ftplib.FTP_TLS): def __init__(self, host='', user='', passwd='', acct='', keyfile=None, certfile=None

ajax方式下载文件

<button type="button" onclick="download()">导出</button> function download() { var url = 'download/?filename=aaa.txt'; var xhr = new XMLHttpRequest(); xhr.open('GET', url, true); // 也可以使用POST方式,根据接口 xhr.responseType = "b

C#利用WebClient 两种方式下载文件

WebClient client = new WebClient(); 第一种 string URLAddress = @"http://files.cnblogs.com/x4646/tree.zip"; string [email protected]"C:\"; client.DownloadFile(URLAddress, receivePath + System.IO.Path.GetFileName(URLAddress)); 就OK了. 第二种 Str