コード例 #1
0
 /// <summary>
 ///   This is a name-based indexer into the Zip archive.
 /// </summary>
 ///
 /// <remarks>
 /// <para>
 ///   This property is read-only.
 /// </para>
 ///
 /// <para>
 ///   The <see cref="CaseSensitiveRetrieval"/> property on the <c>ZipFile</c>
 ///   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.
 /// </para>
 ///
 /// <para>
 ///   Regardless of case-sensitivity, it is not always the case that
 ///   <c>this[value].FileName == value</c>. In other words, the <c>FileName</c>
 ///   property of the <c>ZipEntry</c> retrieved with this indexer, may or may
 ///   not be equal to the index value.
 /// </para>
 ///
 /// <para>
 ///   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, <c>zip["dir1\\entry1.txt"].FileName ==
 ///   "dir1/entry.txt"</c>.
 /// </para>
 ///
 /// <para>
 ///   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.
 /// </para>
 ///
 /// </remarks>
 ///
 /// <example>
 /// This example extracts only the entries in a zip file that are .txt files.
 /// <code>
 /// using (ZipFile zip = ZipFile.Read("PackedDocuments.zip"))
 /// {
 ///   foreach (string s1 in zip.EntryFilenames)
 ///   {
 ///     if (s1.EndsWith(".txt"))
 ///       zip[s1].Extract("textfiles");
 ///   }
 /// }
 /// </code>
 /// <code lang="VB">
 ///   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
 /// </code>
 /// </example>
 ///
 /// <exception cref="System.ArgumentException">
 ///   Thrown if the caller attempts to assign a non-null value to the indexer.
 /// </exception>
 ///
 /// <param name="fileName">
 ///   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
 ///   <see cref="CaseSensitiveRetrieval"/> property to change this behavior. The
 ///   pathname can use forward-slashes or backward slashes.
 /// </param>
 ///
 /// <returns>
 ///   The <c>ZipEntry</c> within the Zip archive, given by the specified
 ///   filename. If the named entry does not exist in the archive, this indexer
 ///   returns <c>null</c> (<c>Nothing</c> in VB).
 /// </returns>
 ///
 public ZipEntry this[String fileName]
 {
     get
     {
         var key = SharedUtilities.NormalizePathForUseInZipFile(fileName);
         if (_entries.ContainsKey(key))
             return _entries[key];
         // workitem 11056
         key = key.Replace("/", "\\");
         if (_entries.ContainsKey(key))
             return _entries[key];
         return null;
     }
 }
コード例 #2
0
 /// <summary>
 ///   Returns true if an entry by the given name exists in the ZipFile.
 /// </summary>
 ///
 /// <param name='name'>the name of the entry to find</param>
 /// <returns>true if an entry with the given name exists; otherwise false.
 /// </returns>
 public bool ContainsEntry(string name)
 {
     // workitem 12534
     return _entries.ContainsKey(SharedUtilities.NormalizePathForUseInZipFile(name));
 }