System.IO.Compression.ZipArchive.GetEntry C# (CSharp) Метод

GetEntry() публичный Метод

Retrieves a wrapper for the file entry in the archive with the specified name. Names are compared using ordinal comparison. If there are multiple entries in the archive with the specified name, the first one found will be returned.
entryName is a zero-length string. entryName is null. The ZipArchive does not support reading. The ZipArchive has already been closed. The Zip archive is corrupt and the entries cannot be retrieved.
public GetEntry ( string entryName ) : ZipArchiveEntry
entryName string A path relative to the root of the archive, identifying the desired entry.
Результат ZipArchiveEntry
        public ZipArchiveEntry GetEntry(string entryName)
        {
            if (entryName == null)
                throw new ArgumentNullException(nameof(entryName));
            Contract.EndContractBlock();

            if (_mode == ZipArchiveMode.Create)
                throw new NotSupportedException(SR.EntriesInCreateMode);

            EnsureCentralDirectoryRead();
            ZipArchiveEntry result;
            _entriesDictionary.TryGetValue(entryName, out result);
            return result;
        }

Same methods

ZipArchive::GetEntry ( string entryName ) : System.IO.Compression.ZipArchiveEntry

Usage Example

Пример #1
1
 public string ReadArchive(Stream archiveStream, string path)
 {
     using (var archive = new ZipArchive(archiveStream, ZipArchiveMode.Read))
     {
         var zipArchiveEntry = archive.GetEntry(path);
         using (var stream = zipArchiveEntry.Open())
         using (var reader = new StreamReader(stream))
         {
             var content = reader.ReadToEnd();
             return content;
         }
     }
 }
All Usage Examples Of System.IO.Compression.ZipArchive::GetEntry