如何获取响应头中的content-disposition

雷劈的心情 2个月前 已收到1个回答 举报

夶雪雪 3星

共回答了356个问题采纳率:91.2% 评论

将上述需求进行归我给出如下例子代码:

public static void ToDownload(string serverfilpath,string filename)

{

FileStream fileStream = new FileStream(serverfilpath, FileMode.Open);

long fileSize = fileStream.Length;

HttpContext.Current.Response.ContentType = "application/octet-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();

}

21小时前

1
可能相似的问题

猜你喜欢的问题

热门问题推荐

Copyright © 2024 微短问答 All rights reserved. 粤ICP备2021119249号 站务邮箱 959505@qq.com