夶雪雪 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小时前
猜你喜欢的问题
5个月前1个回答
5个月前1个回答
5个月前1个回答
5个月前2个回答
5个月前1个回答
5个月前2个回答
热门问题推荐
1个月前1个回答
1个月前1个回答
2个月前2个回答
1个月前2个回答
1个月前2个回答
3个月前1个回答
2个月前3个回答
3个月前1个回答
3个月前3个回答