首页 > 解决方案 > 如何在没有其他 Nuget 包的情况下打开 zip 文件?

问题描述

我有以下代码:

    public static class PracticeFunction 
    {
        [FunctionName("LearningAboutFunctions")]
        public static void Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, ILogger log)
        {
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");

            using (var client = new WebClient())
            {
                client.DownloadFile("https://examplesite.co.uk/file.zip", "myfile.zip");
            }
        }
    }
}

有没有一种方法可以打开 Zip 文件并提取内容而无需安装任何额外的 nuget 包?

标签: c#zip

解决方案


尝试这样的事情

using System.IO.Compression;

string startPath = @"C:\Users\host\Desktop\Folder";
            string zipPath = startPath + @"\Zipfile.zip";
            string extractPath = @"C:\Users\host\Desktop\Final Folder\";
            ZipFile.ExtractToDirectory(zipPath, extractPath);

推荐阅读