Item Property (fileName)

DotNetZip

Ionic Zip Library v1.9.1.6 Item Property (fileName)
ReferenceIonic.ZipZipFileItem[([( String])])
This is a name-based indexer into the Zip archive.
Declaration Syntax
C# Visual Basic Visual C++
public ZipEntry this[
	string fileName
] { get; }
Public ReadOnly Default Property Item ( _
	fileName As String _
) As ZipEntry
	Get
public:
property ZipEntry^ default[String^ fileName] {
	ZipEntry^ get (String^ fileName);
}
Parameters
fileName (String)
The name of the file, including any directory path, to retrieve from the zip. The filename match is not case-sensitive by default; you can use the CaseSensitiveRetrieval property to change this behavior. The pathname can use forward-slashes or backward slashes.
Return Value
The ZipEntry within the Zip archive, given by the specified filename. If the named entry does not exist in the archive, this indexer returns null (Nothing in VB).
Remarks

This property is read-only.

The CaseSensitiveRetrieval property on the ZipFile determines whether retrieval via this indexer is done via case-sensitive comparisons. By default, retrieval is not case sensitive. This makes sense on Windows, in which filesystems are not case sensitive.

Regardless of case-sensitivity, it is not always the case that this[value].FileName == value. In other words, the FileName property of the ZipEntry retrieved with this indexer, may or may not be equal to the index value.

This is because DotNetZip performs a normalization of filenames passed to this indexer, before attempting to retrieve the item. That normalization includes: removal of a volume letter and colon, swapping backward slashes for forward slashes. So, zip["dir1\\entry1.txt"].FileName == "dir1/entry.txt".

Directory entries in the zip file may be retrieved via this indexer only with names that have a trailing slash. DotNetZip automatically appends a trailing slash to the names of any directory entries added to a zip.

Examples
This example extracts only the entries in a zip file that are .txt files.
CopyC#
using (ZipFile zip = ZipFile.Read("PackedDocuments.zip"))
{
  foreach (string s1 in zip.EntryFilenames)
  {
    if (s1.EndsWith(".txt"))
      zip[s1].Extract("textfiles");
  }
}
CopyVB.NET
Using zip As ZipFile = ZipFile.Read("PackedDocuments.zip")
    Dim s1 As String
    For Each s1 In zip.EntryFilenames
        If s1.EndsWith(".txt") Then
            zip(s1).Extract("textfiles")
        End If
    Next
End Using
Exceptions
Exception Condition
ArgumentException Thrown if the caller attempts to assign a non-null value to the indexer.

Assembly: Ionic.Zip (Module: Ionic.Zip) Version: 1.9.1.8 (1.9.1.8)