Compress a file saved in Database

Asked

Viewed 60 times

1

good afternoon! I have a file that is saved in bank, and I need to zip this file, when you download it. How do I do it? Thank you very much for your support

  • already have the code to save the file to disk ? then just use Dotnet.ZIP: example: https://answall.com/q/253856/69359

  • No, I’ll take a look at this link. ?

  • straight from the bank comes an array of bytes, stream, ... I don’t know if it works

  • understood... how do I save the database to disk.

  • What version of . NET Framework are you using, @Ricardosoares?

  • is 4.0 and unfortunately not Ziparchive support

  • With this restriction I think I once used the Dotnetzip library, must have in nuget

  • I’ll try with Ionic. Unfortunately I can’t add other components...

  • But this lib is compatible with Ionic https://www.nuget.org/packages/Ionic.Zip/

Show 4 more comments

1 answer

0

From . NET Framework 4.5 Beta, it is possible to manipulate ZIP files. Example based in this:

using System;
using System.IO;
using System.IO.Compression;
using System.IO.Compression.FileSystem;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            using (FileStream zipToOpen = new FileStream(@"c:\users\exampleuser\Desktop\release.zip", FileMode.Create))
            {
                using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Create))
                {
                    archive.CreateEntryFromFile(@"c:\users\exampleuser\Desktop\MeuArquivoACompactar.dat", "arquivo.dat");
                }
            }
        }
    }
}
  • opa...thanks for the help. but I did it by Ionic, on account of the version of . net

Browser other questions tagged

You are not signed in. Login or sign up in order to post.