Convert Archive Formats (ZIP, 7z, TAR, RAR)

This guide shows how to convert archives between formats (ZIP to 7z, ZIP to TAR, etc.) without modifying the files inside. The archive format changes, but the contents remain unchanged.

To extract and convert files inside archives, see Extract and Convert Archive Contents.

Basic Archive Format Conversion

Convert ZIP to 7z:

using GroupDocs.Conversion;
using GroupDocs.Conversion.Options.Convert;
using GroupDocs.Conversion.FileTypes;

using (var converter = new Converter("archive.zip"))
{
    var options = new CompressionConvertOptions
    {
        Format = CompressionFileType.SevenZ
    };
    converter.Convert("archive.7z", options);
}

Convert ZIP to TAR:

using (var converter = new Converter("documents.zip"))
{
    var options = new CompressionConvertOptions
    {
        Format = CompressionFileType.Tar
    };
    converter.Convert("documents.tar", options);
}

Password Protection

Add password to output archive:

using (var converter = new Converter("data.zip"))
{
    var options = new CompressionConvertOptions
    {
        Format = CompressionFileType.SevenZ,
        Password = "SecurePassword123"
    };
    converter.Convert("data-protected.7z", options);
}

CompressionConvertOptions Properties

PropertyTypeDescription
FormatCompressionFileTypeTarget archive format (ZIP, 7z, TAR, etc.)
PasswordstringOptional password to protect the output archive

Supported Archive Formats

Input (read): ZIP, RAR, 7z, TAR, TAR.GZ, TAR.BZ2, TAR.XZ, CAB, LZ, CPIO, ISO

Output (write): ZIP, 7z, TAR, TAR.GZ, TAR.BZ2, TAR.XZ

Warning
RAR Output Limitation: RAR archives can be read as input but cannot be created as output due to licensing restrictions. Use ZIP, 7z, or TAR as alternatives.

Format Comparison

ZIP - Most compatible, good compression, universal support 7z (SevenZ) - Best compression ratio, open source, requires 7-Zip TAR - Unix/Linux standard, preserves permissions, often used with compression (TAR.GZ) RAR - Input only, cannot be created as output

Batch Processing

Convert multiple archives:

string[] zipFiles = Directory.GetFiles(@"C:\archives", "*.zip");

foreach (var zipFile in zipFiles)
{
    string outputFile = Path.Combine(
        @"C:\converted",
        Path.GetFileNameWithoutExtension(zipFile) + ".7z"
    );

    using (var converter = new Converter(zipFile))
    {
        var options = new CompressionConvertOptions
        {
            Format = CompressionFileType.SevenZ,
            Password = "Batch2024"
        };
        converter.Convert(outputFile, options);
    }
}

Common Scenarios

Cross-platform distribution (ZIP to TAR.GZ):

using (var converter = new Converter("windows-software.zip"))
{
    var options = new CompressionConvertOptions
    {
        Format = CompressionFileType.Gz  // TAR.GZ
    };
    converter.Convert("unix-software.tar.gz", options);
}

Maximum compression (ZIP to 7z):

using (var converter = new Converter("large-dataset.zip"))
{
    var options = new CompressionConvertOptions
    {
        Format = CompressionFileType.SevenZ
    };
    converter.Convert("large-dataset.7z", options);
}

Legacy RAR conversion (RAR to ZIP):

using (var converter = new Converter("old-archive.rar"))
{
    var options = new CompressionConvertOptions
    {
        Format = CompressionFileType.Zip
    };
    converter.Convert("new-archive.zip", options);
}

FluentConverter Alternative

You can also use FluentConverter for archive format conversion:

using GroupDocs.Conversion.Fluent;
using GroupDocs.Conversion.Contracts;

FluentConverter.Load("archive.zip")
    .ConvertTo((SaveContext saveContext) => File.Create("archive.7z"))
    .WithOptions(new CompressionConvertOptions
    {
        Format = CompressionFileType.SevenZ
    })
    .Convert();

The standard Converter API shown above is simpler for basic format conversion.

Limitations

Cannot convert regular documents to archives:

// ❌ THIS WILL FAIL
using (var converter = new Converter("document.pdf"))
{
    var options = new CompressionConvertOptions
    {
        Format = CompressionFileType.Zip
    };
    converter.Convert("output.zip", options);
}

Archives contain multiple files. To extract and convert archive contents, see Working with Archive Files.

See Also

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.