.net 打包下载
ZipArchive 打包下载
private IActionResult DownloadZipFromUrl(string[] guids,string zipFullName)
{
using (MemoryStream zipStream = new MemoryStream())
{
using (System.Net.WebClient webClient = new System.Net.WebClient())
{
using (var archive = new ZipArchive(zipStream, ZipArchiveMode.Create, leaveOpen: true))
{
foreach (var m in guids)
{
if (string.IsNullOrWhiteSpace(m)) continue;
if (m == Guid.Empty.ToString()) continue; #region build url : https://****/upload/image?g=353e7e1b-69ae-4a60-8cfc-3737c2a64eaa&j=false
var builder = new UriBuilder()
{
Scheme = Request.Scheme,
Host = Request.Host.Host,
Path = "upload/image",
Query = "j=false&g=" + m,
};
if (Request.Host.Port != null)
{
builder.Port = Request.Host.Port.Value;
}
#endregion
webClient.DownloadDataCompleted += wc_DownloadDataCompleted;
var attachmentData = webClient.DownloadData(builder.Uri);
ZipArchiveEntry entry = archive.CreateEntry(string.IsNullOrWhiteSpace(_DownloadAttachmentFileName) ? "File1.pdf" : _DownloadAttachmentFileName, System.IO.Compression.CompressionLevel.Fastest);
using (var entryStream = entry.Open())
{
entryStream.Write(attachmentData);
}
}
}
}// disposal of archive will force data to be written to memory stream.
zipStream.Position = 0; //reset memory stream position.
return File(zipStream.ToArray(), "application/vnd.ms-excel", zipFullName);
}
}
获取文件名
private string _DownloadAttachmentFileName = string.Empty;
private void wc_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
{
WebClient wc = sender as WebClient; // Try to extract the filename from the Content-Disposition header
if (!String.IsNullOrEmpty(wc.ResponseHeaders["Content-Disposition"]))
{
_DownloadAttachmentFileName = wc.ResponseHeaders["Content-Disposition"].Substring(wc.ResponseHeaders["Content-Disposition"].IndexOf("filename=") + 10).Replace("\"", ""); //FileName ok }
var data = e.Result; //File OK
}
.net 打包下载的更多相关文章
- ASP.NET五步打包下载Zip文件
本文版权归博客园和作者吴双共同所有,转载和爬虫请注明原文地址:www.cnblogs.com/tdws 首先分享几个振奋人心的新闻: 1.谷歌已经宣布加入.NET基金会 2.微软加入Linux基金会, ...
- 射手网字幕打包下载(73.16G)
射手网陪着我度过15年了. 我所希望射手网所具有的价值,就是能令更多人跨越国家的樊篱,了解世界上不同的文化. 如果这个网站有帮到人,我就已经很满足了. 但是,需要射手网的时代已经走开了. 因此,今天, ...
- 2014年最新720多套Android源码2.0GB免费一次性打包下载
之前发过一个帖子,但是那个帖子有点问题我就重新发一个吧,下面的源码是我从今年3月份开始不断整理源码区和其他网站上的android源码,目前总共有720套左右,根据实现的功能被我分成了100多个类,总共 ...
- ASP.NET 打包下载文件
使用的类库为:ICSharpCode.SharpZipLib.dll 一种是打包整个文件夹,另一种是打包指定的多个文件,大同小异: using ICSharpCode.SharpZipLib.Zip; ...
- C#.NET快速开发框架-企业版V4.0截图打包下载
C/S系统开发框架-企业版 V4.0 (Enterprise Edition) http://www.csframework.com/cs-framework-4.0.htm 其它图片打包下载: ht ...
- ASP.NET多文件批量打包下载
在对多文件打包中用到了 DotNetZip 的方法来实现对多文件压缩打包.需要到http://dotnetzip.codeplex.com/处下载该文件,然后引用即可. Default.aspx: & ...
- 开源 & 免费使用 & 打包下载自行部署 :升讯威 周报系统
这个周报系统大约写于2015年,缘起当时所带的开发团队需要逐步建立或完善一些项目管理方法. 在调研了网上的诸多项目管理或周报/日报管理系统之后,并没有找到符合当时情况的系统,这里最大的问题不是网上既有 ...
- java 实现多文件打包下载
jsp页面js代码: function downloadAttached(){ var id = []; id.push(infoid); var options = {}; options.acti ...
- PHP实现zip压缩打包下载
先来看PHP实现文件及文件夹的zip压缩 这里使用PHP扩展的ZipArchive类,在使用之前要将php.ini文件中的zlib.output_compression设置为On 代码如下: publ ...
- js证书批量生成与打包下载
前边有提到最近的一个证书生成保存下载打印的需求. 之前实现的是一个单个操作的页面,现在把实现的批量效果和进度效果的代码展示出来. html <button class="btn btn ...
随机推荐
- AmiGO2:在线浏览和查询GO信息的利器
GO数据库的信息是非常庞大的,为了有效的检索和浏览GO数据库的信息,官方提供了AmiGO, 可以方便的浏览,查询和下载对应信息,官网如下 http://amigo.geneontology.org/a ...
- Axis2基础
本章主要介绍如何使用axis2开发webservice接口. 以下以一个实例程序讲解如何编写一个axis2的服务端和客户端. axis2版本:axis2-1.5.4-bin.zip 目录结构: 关键代 ...
- 在Eclipse下配置算法(第四版)运行环境
第一步:配置Eclipse运行环境 Eclipse运行环境配置过程是很简单的,用过Eclipse进行java开发或学习的同学应该都很熟悉这个过程了. 配置过程: (1)系统环境:Windows7 64 ...
- 几种线程安全的Map解析
转载自 面试必问-几种线程安全的Map解析 HashMap线程安全的吗? Java中平时用的最多的Map集合就是HashMap了,它是线程不安全的. 看下面两个场景: 1.当用在方法内的局部变量时,局 ...
- mxnet设置动态学习率(learning rate)
https://blog.csdn.net/xiaotao_1/article/details/78874336 如果learning rate很大,算法会在局部最优点附近来回跳动,不会收敛: 如果l ...
- Nginx和PHP上传文件大小的限制
Nginx client_max_body_size 80m; PHP php.ini file_uploads = on ; 是否允许通过HTTP上传文件的开关.默认为ON即是开 upload_tm ...
- PHP 支付类库, cURL开源HTTP类库
未做任何测试 支付类库地址:http://doc.yurunsoft.com/PaySDK cURL开源HTTP类库地址:http://doc.yurunsoft.com/YurunHttp/1
- Spring Boot(十二):spring boot如何测试打包部署
Spring Boot(十二):spring boot如何测试打包部署 一.开发阶段 1,单元测试 在开发阶段的时候最重要的是单元测试了,springboot对单元测试的支持已经很完善了. (1)在p ...
- End of script output before headers错误解决方法
注意是否丢失两个换行符\n\n printf("Content-type: text/html;charset=utf-8\n\n");
- 关于__declspec(dllexport)
windows下dll动态库函数的导入与导出. __declspec Microsoft Specific __declspec ( extended-attribute ) declarator l ...