.NET 3.x Как использовать SharpCompress для упаковки файлов - C#

Узнай цену своей работы

Формулировка задачи:

Как использовать SharpCompress сжимать в rar скинте пример упаковки файла одного , и папки c паролем, и распаковки аналогично все подключил SharpCompress
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpCompress;
using System.IO;
using SharpCompress.IO;
using SharpCompress.Compressor;
using SharpCompress.Archive;
using SharpCompress.Reader;
using SharpCompress.Writer;
 
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

        }
    }
}
а код какой не знаю гуглил не нашел

Решение задачи: «.NET 3.x Как использовать SharpCompress для упаковки файлов»

textual
Листинг программы
using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
//using System.Threading.Tasks;
using System.IO;
using SharpCompress;
using SharpCompress.IO;
using SharpCompress.Compressor;
using SharpCompress.Archive;
using SharpCompress.Common;
using SharpCompress.Reader;
using SharpCompress.Archive.Zip;
using SharpCompress.Writer;
 
namespace Arhiv_test
{
    class Program
    {
        //static SharpCompress.Archive.Zip.ZipArchive zip =new SharpCompress.Archive.Zip.ZipArchive();
        static void Main(string[] args)
        {
 
            arh_zip("folder","arhivzip.zip");
        }
        // не работает по примеру 
        static void arh_zip (string folderpatch,string name_zip)
        {
            using (var archive = ZipArchive.Create())
            {
                DirectoryInfo dir_files = new DirectoryInfo(folderpatch);
                archive.AddAllFromDirectoryEntry(dir_files.FullName);
                archive.SaveTo(dir_files.FullName+"\\"+name_zip);
                Console.WriteLine("extract end..............");
                Console.ReadKey(true);
            }
        }
 
        static void arhiv (string arh)
        {
 
            FileInfo fi = new FileInfo(arh);
            using (Stream stream = File.OpenRead(fi.Name))
            {
                var reader = ReaderFactory.Open(stream);
                while (reader.MoveToNextEntry())
                {
 
                    if (!reader.Entry.IsDirectory)
                    {
                        Console.WriteLine(reader.Entry.FilePath);
                        reader.WriteEntryToDirectory(fi.Directory.FullName + "\\" + "res", ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite);
                        Console.WriteLine("extract end..............");
                        Console.ReadKey(true);
                    }
                }
            }
 
        }
 
 
    }
}

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

7   голосов , оценка 4.286 из 5
Похожие ответы