zoukankan
html css js c++ java
文件下载源码
public
void
DownLoad(
string
FileName,Page R)
{
if
(FileName
!=
""
)
{
string
path
=
R.Server.MapPath(FileName);
System.IO.FileInfo file
=
new
System.IO.FileInfo(path);
if
(file.Exists)
{
R.Response.Clear();
R.Response.AddHeader(
"
Content-Disposition
"
,
"
attachment; FileName=
"
+
file.Name);
R.Response.AddHeader(
"
Content-Length
"
, file.Length.ToString());
R.Response.ContentType
=
"
application/octet-stream
"
;
R.Response.Filter.Close();
R.Response.WriteFile(file.FullName);
R.Response.End();
}
else
{
R.Response.Write(
"
This file does not exist.
"
);
}
}
示例 二:
private
void
NewDownLoad(
string
Path,
string
FileName)
{
//
Path为文件绝对路径,FileName为文件路径
FileStream fs
=
new
FileStream(Path,FileMode.Open,FileAccess.Read);
BinaryReader r
=
new
BinaryReader(fs);
Response.AddHeader(
"
Content-Disposition
"
,
"
attachment;filename=
"
+
FileName);
Response.Charset
=
"
gb2312
"
;
Response.ContentType
=
"
application/octet-stream
"
;
Response.BinaryWrite(r.ReadBytes(Convert.ToInt32(fs.Length)));
Response.Flush();
fs.Close();
try
{
File.Delete(Path);
}
catch
(System.Exception ee)
{
string
ff
=
ee.ToString();
}
}
示例三:
文件下载
#region
文件下载
private
void
DownLoadFile(
string
address,
string
filename)
{
//
address 文件下载路径,filename文件存放的本地路径
WebClient client
=
new
WebClient();
client.DownloadFile(address,filename);
Stream str
=
client.OpenRead(address);
StreamReader reader
=
new
StreamReader(str);
byte
[] mbyte
=
new
byte
[str.Length
+
1
];
int
allmybyte
=
(
int
)mbyte.Length;
int
startmbyte
=
0
;
while
(allmybyte
>
0
)
{
int
m
=
str.Read(mbyte,startmbyte,allmybyte);
if
(m
==
0
)
{
break
;
}
startmbyte
+=
m;
allmybyte
-=
m;
}
FileStream fstr
=
new
FileStream(filename,FileMode.OpenOrCreate,FileAccess.Write);
fstr.Write(mbyte,
0
,startmbyte);
str.Close();
fstr.Close();
}
#endregion
查看全文
相关阅读:
阶梯博弈
hihoCoder #1199 : Tower Defense Game ——(树型dp)
2016 China-Final-F题 ——(SA+二分)
ACM之路(20)—— Splay初探
2016 ICPC China-Final 现场赛总结
【Interleaving String】cpp
【Best Time to Buy and Sell Stock III 】cpp
【Maximal Rectangle】cpp
【palindrome partitioning II】cpp
【Maximum Subarray 】cpp
原文地址:https://www.cnblogs.com/sunheyubo/p/881677.html
最新文章
入门级的PHP验证码
centos5.4下mysql主从复制
mysql主从备份、主从切换的例子
CentOS安全设置
CentOS设置服务开机启动的方法
Android实现XML解析技术
BroadcastReceiver的使用和两种注册方式使用及区别
Android单元测试初探Instrumentation
Android之Textview使用
Android 4.0 Tabhost图标显示不出来
热门文章
ScrollView:ScrollView can host only one direct child异常
android gravity属性 和 weight属性
Android中文API
(转)在Myeclipse中查看android源码就是这么easy
android素材资源
CodeForces Good Bye 2016
Codeforces Round #388 (Div. 2)
CodeForces 754C Vladik and chat ——(xjbg)
CodeForces 754D Fedor and coupons ——(k段线段最大交集)
zstuoj 4243 牛吃草 ——(二分+两圆交)
Copyright © 2011-2022 走看看