惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The GitHub Blog
The GitHub Blog
S
SegmentFault 最新的问题
MyScale Blog
MyScale Blog
有赞技术团队
有赞技术团队
V
Visual Studio Blog
T
The Blog of Author Tim Ferriss
爱范儿
爱范儿
Vercel News
Vercel News
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Y
Y Combinator Blog
Blog — PlanetScale
Blog — PlanetScale
D
DataBreaches.Net
美团技术团队
Microsoft Security Blog
Microsoft Security Blog
大猫的无限游戏
大猫的无限游戏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
酷 壳 – CoolShell
酷 壳 – CoolShell
GbyAI
GbyAI
A
About on SuperTechFans
云风的 BLOG
云风的 BLOG
The Cloudflare Blog
宝玉的分享
宝玉的分享
V
V2EX
Microsoft Azure Blog
Microsoft Azure Blog

博客园 - iDEAAM

logstash 如何从oracle 导入 pgsql IIS如何部署python django项目 IIS 如何部署net8 和 如何配置反向代理 ARR、URL Rewrite python 备份文件,从 D盘 到Z盘。并且保留15天的文件 git 如何排除 bin obj nginx 配置 自签名https证书 powershell 计划任务 定时任务 如何调用get接口 使用nssm在windows服务器上部署nodejs 退出远程桌面不锁屏 PDF 转 Excel 非常完美的java包 sublime 选择有规律的数据,同时快速编辑多行内容 去除重复行或者只保留唯一值 C#中 同步方法调用异步方法不死锁的方法 async await task windows 2008 r2 iis https 配置方法 vue js中,利用json数据临时生成一个可下载csv的功能 git常用命令 从 ASP.NET MVC 和 Web API 升级到 ASP.NET Core MVC c# 把现有图片顶部top50px 处理成白色 C# asp.net开源插件推荐:PdfiumViewer ( pdf 转成 图片png pdf convert to image ) 在asp.net mvc中使用了owin startup如何使用 swagger插件
C#下载远程文件并打包
iDEAAM · 2023-11-21 · via 博客园 - iDEAAM
using System;
using System.IO;
using System.IO.Compression;
using System.Net;

class Program
{
    static void Main()
    {
        string[] files = {

"http://www.xxx.com/xx1.xls",
"http://www.xxx.com/xx2.xls",
        };

        string output = "files.zip";

        using (FileStream newZipFile = new FileStream(output, FileMode.Create))
        {
            using (ZipArchive zipArchive = new ZipArchive(newZipFile, ZipArchiveMode.Create))
            {
                foreach (string fileURL in files)
                {
                    string fileName = Path.GetFileName(fileURL);
                    byte[] fileBytes = DownloadFile(fileURL);
                    if (fileBytes != null)
                    {
                        ZipArchiveEntry zipEntry = zipArchive.CreateEntry(fileName, CompressionLevel.Fastest);
                        using (Stream entryStream = zipEntry.Open())
                        {
                            entryStream.Write(fileBytes, 0, fileBytes.Length);
                        }
                    }
                }
            }
        }

        Console.WriteLine("Zipped File: " + output);
    }

    static byte[] DownloadFile(string url)
    {
        using (WebClient client = new WebClient())
        {
            try
            {
                return client.DownloadData(url);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return null;
            }
        }
    }
}

posted @ 2023-11-21 13:48  iDEAAM  阅读(170)  评论()    收藏  举报