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
查看全文
相关阅读:
python简单的运算
Typora的基本格式使用
在Eclipse中在线安装Emmet和图文使用教程
6月末的总结
TF-IDF学习笔记
idea调试SpringMvc, 出现:”Can't find catalina.jar"错误的解决方法
idea调试SpringMvc, 出现:”javax.servlet.ServletException: java.lang.IllegalStateException: Cannot create a session after the response has been committed"错误的解决方法
idea调试SpringMvc, 出现:”通配符的匹配很全面, 但无法找到元素 'mvc:annotation-driven' 的声明“错误的解决方法
idea调试SpringMvc, 出现:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener错误的解决办法
Zabbix 漏洞分析
原文地址:https://www.cnblogs.com/sunheyubo/p/881677.html
最新文章
使用docker搭建redis主从模式
Redis进阶实践之五Redis的高级特性
Redis进阶实践之四Redis的基本数据类型
R语言数据整理
Writing Genres 英文文章文体
学习是一个漫长不能松懈的过程
Eclipse语言的切换方法
iframe自适应高度
asp.net报错“尝试读取或写入受保护的内存。这通常指示其他内存已损坏”的解决办法
如何获取repeater某行第一列的值
热门文章
ASP.NET中的几种弹出框提示
SQL 自增列清零方法
DBHelper
SQL 判断表是否存在
利用"SQL"语句自动生成序号的两种方式
jade的写法
字符串的使用练习
turtle绘画哆啦A梦
python简单的运算(二)
计算机的介绍
Copyright © 2011-2022 走看看