共用方式為


ZipArchiveEntry.Length 屬性

定義

取得 zip 封存中專案的未壓縮大小,以位元組表示。

public:
 property long Length { long get(); };
public long Length { get; }
member this.Length : int64
Public ReadOnly Property Length As Long

屬性值

Zip 封存中的項目未壓縮大小。

例外狀況

屬性的值無法使用,因為該項目已被修改。

範例

下列範例示範如何從 zip 封存擷取專案,並評估項目的屬性。 它會使用 Name 屬性來顯示項目的名稱,以及 LengthCompressedLength 屬性來計算壓縮檔案的數目。

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string zipPath = @"c:\example\result.zip";

            using (ZipArchive archive = ZipFile.OpenRead(zipPath))
            {
                foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    float compressedRatio = (float)entry.CompressedLength / entry.Length;
                    float reductionPercentage = 100 - (compressedRatio * 100);

                    Console.WriteLine (string.Format("File: {0}, Compressed {1:F2}%", entry.Name, reductionPercentage));
                }
            }
        }
    }
}
Imports System.IO
Imports System.IO.Compression

Module Module1

    Sub Main()
        Dim zipPath As String = "c:\example\result.zip"

        Using archive As ZipArchive = ZipFile.OpenRead(zipPath)
            For Each entry As ZipArchiveEntry In archive.Entries
                Dim compressedRatio As Single = entry.CompressedLength / entry.Length
                Dim reductionPercentage As Single = 100 - (compressedRatio * 100)

                Console.WriteLine(String.Format("File: {0}, Compressed {1:F2}%", entry.Name, reductionPercentage))
            Next
        End Using
    End Sub

End Module

備註

當模式設定為 Create,或模式設定 Update 為 且專案已開啟時,便無法擷取這個屬性。

適用於