通过RestSharp解压缩下载的文件

时间:2017-08-09 12:34:44

标签: c# api download zip restsharp

我刚刚使用RestSharp下载了一个.zip文件,效果很好。 这是我的代码:

private void button3_Click(object sender, EventArgs e)
    {
        var client = new RestClient("http://xxx:3080");
        var request = new RestRequest("/xxx/api/download/book/46795403-de-DE", Method.GET);
        request.AddHeader("Authorization", "Bearer Tokenxxx");
        client.DownloadData(request).SaveAs("C:/Users/xxx/Desktop/myRestSharpResponse.zip");
    }

我现在如何自动解压缩文件?

1 个答案:

答案 0 :(得分:1)

使用ZipFile解压缩您的文件:

const string zipPath = @"C:/Users/xxx/Desktop/myRestSharpResponse.zip";
const string extractPath = @"C:/Users/xxx/Desktop/ExtractFolder";

client.DownloadData(request).SaveAs(zipPath);

ZipFile.ExtractToDirectory(zipPath, extractPath);