将上述需求进行归我给出如下例子代码:public static void ToDownload(string serverfilpath,string filename){FileStream fil。如何获取响应头中的content-disposition?更多详情请大家跟着小编一起来看看吧!
如何获取响应头中的content-disposition(1)
将上述需求进行归我给出如下例子代码:
public static void ToDownload(string serverfilpath,string filename)
{
FileStream fileStream = new FileStream(serverfilpath, FileMode.Open);
long fileSize = fileStream.Length;
HttpContext.Current.Response.ContentType = \"applicationoctet-stream\";
HttpContext.Current.Response.AddHeader(\"Content-Disposition\", \"attachment; filename=\\\"\" + UTF_FileName(filename) + \"\\\";\");
attachment --- 作为附件下载
inline --- 在线打开
HttpContext.Current.Response.AddHeader(\"Content-Length\", fileSize.ToString());
byte[] fileBuffer = new byte[fileSize];
fileStream.Read(fileBuffer, 0, (int)fileSize);
HttpContext.Current.Response.BinaryWrite(fileBuffer);
fileStream.Close();
HttpContext.Current.Response.End();
}