当前位置:网站首页>asp. Net file download demo and related problems
asp. Net file download demo and related problems
2022-06-23 07:03:00 【Wool leek】
Download the demo( Total size of displayable files , And solves the problem that the download ends automatically after the download is completed )
// Download in blocks
private void downLoadPackage()
{
System.Web.HttpServerUtility server = System.Web.HttpContext.Current.Server;
string fileName = "aaa.apk";
// route
string filePath = server.MapPath("DownLoadPackage/aaa.apk");
if (!File.Exists(filePath)) return;
FileInfo info = new FileInfo(filePath);
// Specify block size
long chunkSize = 4096;
// Build a 4K The buffer
byte[] buffer = new byte[chunkSize];
// The number of bytes left
long dataToRead = 0;
FileStream stream = null;
try
{
// Open file
stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
dataToRead = stream.Length;
// add to Http head
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachement;filename=" + HttpUtility.UrlEncode(fileName));
HttpContext.Current.Response.AddHeader("Content-Length", dataToRead.ToString());
while (dataToRead > 0)
{
if (HttpContext.Current.Response.IsClientConnected)
{
int length = stream.Read(buffer, 0, Convert.ToInt32(chunkSize));
HttpContext.Current.Response.OutputStream.Write(buffer, 0, length);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Clear();
dataToRead -= length;
}
else
{
// prevent client Lose connection
dataToRead = -1;
}
}
}
catch (Exception ex)
{
HttpContext.Current.Response.Write("Error:" + ex.Message);
}
finally
{
if (stream != null)
{
stream.Close();
}
HttpContext.Current.Response.Close();
}
}
iis Cannot download on .apk and .ipa The problem of
single click “ newly build ”, Set up new MIME type ;
The extension is :.apk MIMI The type is :application/vnd.android.package-archive
The extension is :.ipa MIMI The type is :application/iphone
边栏推荐
- MySQL Redo log Redo log
- DQL、DML、DDL、DCL的概念与区别
- 【项目实训】多段线扩充为平行线
- [bull Chinese document] queue package used to process distributed jobs and messages in nodejs
- Business logic design of physical warehouse and virtual warehouse in middle inventory
- GIS实战应用案例100篇(七十九)-多规整合底图的制作要点
- Cetos7 record
- [QT] basic learning notes
- 嵌入式实时系统线程的副作用
- 开源OAuth2框架 实现SSO单点登录
猜你喜欢

Easy EDA learning notes 09 esp32-wroom-32e module esp32-devkitc-v4 development board one click download circuit

MySQL redo log redo log

XXL-SSO 实现SSO单点登录

【STL】顺序容器之deque用法总结

MySQL MVCC多版本并发控制

ssm + ftp +ueditor

Xxl-sso enables SSO single sign on

Badly placed()'s problem
![[STL] unordered of associated container_ Map Usage Summary](/img/6a/d614f2f363fa5181c25e79ff8b0dab.png)
[STL] unordered of associated container_ Map Usage Summary

TP6+Redis+think-queue+Supervisor实现进程常驻消息队列/job任务
随机推荐
[STL] summary of deque usage of sequential containers
XML schema record
Eureka
.h5文件忘记数据库名字,使用h5py打印
cmder
What you need to know about five insurances and one fund
xml dtd 记录
mongodb 记录
数据统计与分析基础 实验一 基本语法及运算
Summarized benefits
宝塔忘记密码
MySQL MVCC多版本并发控制
[shell] tree command
【STL】关联容器之map用法总结
Anti chicken soup speech
295. 数据流的中位数
图解三次握手四次挥手,小白都能看懂
C语言运算符优先级口诀
[STL] summary of map usage of associated containers
313. 超级丑数