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 打包下载的更多相关文章

  1. ASP.NET五步打包下载Zip文件

    本文版权归博客园和作者吴双共同所有,转载和爬虫请注明原文地址:www.cnblogs.com/tdws 首先分享几个振奋人心的新闻: 1.谷歌已经宣布加入.NET基金会 2.微软加入Linux基金会, ...

  2. 射手网字幕打包下载(73.16G)

    射手网陪着我度过15年了. 我所希望射手网所具有的价值,就是能令更多人跨越国家的樊篱,了解世界上不同的文化. 如果这个网站有帮到人,我就已经很满足了. 但是,需要射手网的时代已经走开了. 因此,今天, ...

  3. 2014年最新720多套Android源码2.0GB免费一次性打包下载

    之前发过一个帖子,但是那个帖子有点问题我就重新发一个吧,下面的源码是我从今年3月份开始不断整理源码区和其他网站上的android源码,目前总共有720套左右,根据实现的功能被我分成了100多个类,总共 ...

  4. ASP.NET 打包下载文件

    使用的类库为:ICSharpCode.SharpZipLib.dll 一种是打包整个文件夹,另一种是打包指定的多个文件,大同小异: using ICSharpCode.SharpZipLib.Zip; ...

  5. C#.NET快速开发框架-企业版V4.0截图打包下载

    C/S系统开发框架-企业版 V4.0 (Enterprise Edition) http://www.csframework.com/cs-framework-4.0.htm 其它图片打包下载: ht ...

  6. ASP.NET多文件批量打包下载

    在对多文件打包中用到了 DotNetZip 的方法来实现对多文件压缩打包.需要到http://dotnetzip.codeplex.com/处下载该文件,然后引用即可. Default.aspx: & ...

  7. 开源 & 免费使用 & 打包下载自行部署 :升讯威 周报系统

    这个周报系统大约写于2015年,缘起当时所带的开发团队需要逐步建立或完善一些项目管理方法. 在调研了网上的诸多项目管理或周报/日报管理系统之后,并没有找到符合当时情况的系统,这里最大的问题不是网上既有 ...

  8. java 实现多文件打包下载

    jsp页面js代码: function downloadAttached(){ var id = []; id.push(infoid); var options = {}; options.acti ...

  9. PHP实现zip压缩打包下载

    先来看PHP实现文件及文件夹的zip压缩 这里使用PHP扩展的ZipArchive类,在使用之前要将php.ini文件中的zlib.output_compression设置为On 代码如下: publ ...

  10. js证书批量生成与打包下载

    前边有提到最近的一个证书生成保存下载打印的需求. 之前实现的是一个单个操作的页面,现在把实现的批量效果和进度效果的代码展示出来. html <button class="btn btn ...

随机推荐

  1. 基于word2vec训练词向量(二)

    转自:http://www.tensorflownews.com/2018/04/19/word2vec2/ 一.基于Hierarchical Softmax的word2vec模型的缺点 上篇说了Hi ...

  2. Spring 知识点提炼-转

    https://www.cnblogs.com/baizhanshi/p/7717563.html 1. Spring框架的作用 轻量:Spring是轻量级的,基本的版本大小为2MB 控制反转:Spr ...

  3. Unable to open socket file: target process not responding or HotSpot VM not loaded

    Unable to open socket file: target process not responding or HotSpot VM not loaded The -F option can ...

  4. oracle函数,游标,视图使用总结

    oracle函数或者叫存储过程,在实际的开发过程中对于复杂的业务需求是非常有用的,非常有效率的也是非常好玩儿的一个技术点. 平常在开发过程中对于CRUD功能较多.一般SQL即可应付,大不了就是长一点而 ...

  5. html5水平方向重力感应

    html5图片随手机重力感应而移动 <!DOCTYPE html> <html lang="zh-cn"><head><meta http ...

  6. Shell 比较两个数的大小

    格式很重要多一个空格少一个空格都可能出错 li@ubuntu:~/test$ cat compare.sh #!/bin/bash read x read y if [ $x -lt $y ] the ...

  7. HDU 3172 Virtual Friends (map+并查集)

    These days, you can do all sorts of things online. For example, you can use various websites to make ...

  8. Python+OpenCV图像处理(八)—— 图像直方图

    直方图简介:图像的直方图是用来表现图像中亮度分布的直方图,给出的是图像中某个亮度或者某个范围亮度下共有几个像素.还不明白?就是统计一幅图某个亮度像素数量.比如对于灰度值12,一幅图里面有2000 个像 ...

  9. 安装启动kafka

    vim kafka/config/server.properties #确保唯一 broker.id=0 #允许删除主题 delete.topic.enable=true # 指定数据文件所在目录 l ...

  10. 关于scrapy下载文件重命名的办法以及对应url没有文件后缀的办法

    https://www.jianshu.com/p/d1bb28cbb6a8 scrapy中负责下载文件的是class MyFilesPipeline(FilesPipeline)类 其中负责下载文件 ...