需要使用c#ZIP Azure Blob容器 [英] Need to ZIP Azure Blob Container using c#

查看:65
本文介绍了需要使用c#ZIP Azure Blob容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI,



我正在使用Windows Azure。我需要代码来压缩Azure本身的文件夹(容器)。然而,现在我没有从互联网上获得任何代码。



谢谢

Sarath



I am working on windows Azure. And I need the code to Zip the folder(Containers) in Azure itself . Yet now i did not get any code from Internet.

Thanks
Sarath

推荐答案

你需要下载 DotNetZip.Dll 文件并使用..



下面是一些非常简化的代码,显示了这个过程:



U need to download DotNetZip.Dll file and use..

Below is some very stripped down code showing the process:

using (ZipFile zipFile = new ZipFile())
{
    foreach (var uri in uriCollection)
    {
        var blob = new CloudBlob(uri);

        byte[] fileBytes = blob.DownloadByteArray();

        using (var fileStream = new MemoryStream(fileBytes))
        {
            fileStream.Seek(0, SeekOrigin.Begin);
            
            //U May avoid encryption 
            byte[] bytes = CryptoHelp.EncryptAsBytes(fileStream, "password", null);

            zipFile.AddEntry("entry name", bytes);
        }
    }

    using (var zipStream = new MemoryStream())
    {
        zipFile.Save(zipStream);
        zipStream.Seek(0, SeekOrigin.Begin);

        var blobRef = ContainerDirectory.GetBlobReference("output uri");
        blobRef.UploadFromStream(zipStream);
    }

}


这篇关于需要使用c#ZIP Azure Blob容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆