zoukankan
html css js c++ java
对文件下载的补充
我在
ASP.NET中常用的文件上传下载方法
一文中写了几种文件上传下载的方法,其中第二部分的下载当时没有具体说清楚,现在补充一下。对于有具体物理路径的文件下载,我们可以采用下面的思路,先将其转化成二进制流,然后用浏览器读出来,具体代码如下:
/**/
///
<summary>
///
下载文件
///
</summary>
///
<param name="path">
文件所在的物理路径
</param>
///
<param name="fileName">
文件名称
</param>
///
<param name="contentType">
客户端MIME类型
</param>
private
void
UpLoadFile(
string
path,
string
fileName,
string
contentType)
{
FileInfo fi
=
new
FileInfo(path);
FileStream fs
=
fi.OpenRead();
byte
[] FileArray
=
new
byte
[(
int
)fs.Length];
fs.Read(FileArray,
0
, FileArray.Length);
fs.Close();
Response.Buffer
=
true
;
Response.Clear();
Response.ContentType
=
contentType;
Response.AddHeader(
"
Content-Disposition
"
,
"
attachment;filename=
"
+
fileName);
Response.BinaryWrite(FileArray);
Response.Flush();
Response.End();
}
查看全文
相关阅读:
poj1631 LIS 裸题
UESTC 电子科大专题训练 DP-N
UESTC 电子科大专题训练 DP-M
UESTC 电子科大专题训练 DP-D
Codeforces Round #424 D
Codeforces Round #424 C
Codeforces Round #424 B
Codeforces Round #424 A
hiho一下159
hiho一下158(hihocoder 1318)
原文地址:https://www.cnblogs.com/pw/p/673429.html
最新文章
cf- Educational Codeforces Round 40 -D
hdu-6165(tarjan+topusort)
poj2186(tarjan缩点)
hdu-1058(map)
hdu-1421(dp)
hdu-1176(dp)
hdu-2717(基础搜索bfs)
hdu1878-并查集,欧拉回路
训练赛-Building Numbers
训练赛-Eyad and Math
热门文章
hdu 6140
hdu 6143
2017 Multi-University Training Contest
hihocoder 1552
hihocoder 1550
Codeforces Round #380 (Div. 2,) D
Codeforces Round #380 (Div. 2,) C C. Road to Cinema
百度之星初赛B轮 hdu 6114 6118 6119
百度之星初赛A轮 hdu 6108 6112 6113
Codeforces Round #428 (Div. 2)
Copyright © 2011-2022 走看看