Share via


ZipArchive.GetEntry(String) Yöntem

Tanım

Zip arşivinde belirtilen giriş için bir sarmalayıcı alır.

public:
 System::IO::Compression::ZipArchiveEntry ^ GetEntry(System::String ^ entryName);
public System.IO.Compression.ZipArchiveEntry GetEntry (string entryName);
public System.IO.Compression.ZipArchiveEntry? GetEntry (string entryName);
member this.GetEntry : string -> System.IO.Compression.ZipArchiveEntry
Public Function GetEntry (entryName As String) As ZipArchiveEntry

Parametreler

entryName
String

Alınacak girişi tanımlayan, arşivin köküne göre bir yol.

Döndürülenler

Arşivde belirtilen girdi için sarmalayıcı; null girdisi arşivde yoksa.

Özel durumlar

entryName, Empty değeridir.

entryName, null değeridir.

Zip arşivi okumayı desteklemiyor.

Zip arşivi atıldı.

Zip arşivi bozuk ve girdileri alınamıyor.

Örnekler

Aşağıdaki örnekte, bir girişi almak için yönteminin GetEntry nasıl kullanılacağı gösterilmektedir.

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.Open(zipPath, ZipArchiveMode.Update))
            {
                ZipArchiveEntry entry = archive.GetEntry("ExistingFile.txt");
                using (StreamWriter writer = new StreamWriter(entry.Open()))
                {
                    writer.BaseStream.Seek(0, SeekOrigin.End);
                    writer.WriteLine("append line to file");
                }
                entry.LastWriteTime = DateTimeOffset.UtcNow.LocalDateTime;
            }
        }
    }
}
open System
open System.IO
open System.IO.Compression

[<EntryPoint>]
let main _ =
    let zipPath = @"c:\example\result.zip"

    use archive = ZipFile.Open(zipPath, ZipArchiveMode.Update)

    let entry = archive.GetEntry "ExistingFile.txt"
    use writer = new StreamWriter(entry.Open())

    writer.BaseStream.Seek(0, SeekOrigin.End) |> ignore
    writer.WriteLine "append line to file"

    entry.LastWriteTime <- DateTimeOffset.UtcNow.LocalDateTime
    0
Imports System.IO
Imports System.IO.Compression

Module Module1

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

        Using archive As ZipArchive = ZipFile.Open(zipPath, ZipArchiveMode.Update)
            Dim entry As ZipArchiveEntry = archive.GetEntry("ExistingFile.txt")

            Using writer As StreamWriter = New StreamWriter(entry.Open())
                writer.BaseStream.Seek(0, SeekOrigin.End)
                writer.WriteLine("append line to file")
            End Using
            entry.LastWriteTime = DateTimeOffset.UtcNow.LocalDateTime
        End Using
    End Sub

End Module

Açıklamalar

Arşivde belirtilen ada sahip birden çok girdi varsa, ilki döndürülür. Girdinin adı sıralı karşılaştırma kullanılarak entryName karşılaştırılır.

Şunlara uygulanır