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
查看全文
相关阅读:
ubuntu系统里常用的几个命令
Vue中常用知识点demo
Vue基础知识学习(后端)
ubuntu内lnmp相关操作命令
linux下安装lnmp集成环境
js时间戳与日期格式之间相互转换
yii2中 选择布局的方式,可以设置不使用布局
yii2中通过migration创建数据表
php实现支付宝在线支付和扫码支付demo
linux下添加用户并将文件夹授权给某一个用户
原文地址:https://www.cnblogs.com/sunheyubo/p/881677.html
最新文章
复习下SQL基础知识
ambari本地源自动化安装hortonworks hadoop(转)
Oracle面试题之:复杂的查询与实例解析 (转发)
nginx 防盗链+动静分离+反向代理+缓存+负载均衡 (转发)
Linux笔记_Linux系统下如何查看及修改文件读写权限
AOP技术基础
AspnetPage分页控件
风的UV分量转成风向风速(C#)
C#关于winforms窗体大小、边框、移动、动画等属性
C# cmd执行命令
热门文章
C# 利用占位符替换word中的字符串和添加图片
C# 图片的裁剪,两个图片合成一个图片
c#文本框限制输入内容
C# 将容器内容转成图片导出
MICAPS二次开发一些功能调用
c# DataGridView 的一些属性设置,序号,合并头
flex 添加svn插件
微信js-sdk开发获取签名和获取地理位置接口示例
根据数字获取Excel的列,比如 输入 1 得到 A,输入26 得到 Z, 输入 29 得到 AC
php二维数组获取某个字段最大或最小的项,包括键名和键值
Copyright © 2011-2022 走看看