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
查看全文
相关阅读:
铺地毯
解方程
引水入城
10.16今日暂时停更博客
聪明的质监员
CCF NOI plus 201(7)6 初赛题 解题报告
初赛可能会用到的计算机基础理论知识整理
火柴排队
借教室
10.10今日暂时停更博客
原文地址:https://www.cnblogs.com/sunheyubo/p/881677.html
最新文章
B-xor_2019牛客暑期多校训练营(第四场)
hdu-6579 Operation
I-string_2019牛客暑期多校训练营(第四场)
A-Graph Games_2019牛客暑期多校训练营(第三场)
D-Big Integer_2019牛客暑期多校训练营(第三场)
E-triples II_2019牛客暑期多校训练营(第四场)
J-Subarray_2019牛客暑期多校训练营(第二场)
不知道该起什么名字的随笔
买礼物
灾后重建
热门文章
营救
文化之旅
口袋的天空
修复公路
蚯蚓
合并序列
书的复制
丢瓶盖
网线切割
木材切割
Copyright © 2011-2022 走看看