# C1.Zip.C1ZipFile.Open

## Content

<div class="doc-site-dotnet-api-container">



<h1 id="C1_Zip_C1ZipFile_Open_" data-uid="C1.Zip.C1ZipFile.Open*">Open Method
</h1>
<div class="markdown level0 summary"></div>
<div class="markdown level0 conceptual"></div>



<a id="C1_Zip_C1ZipFile_Open_" data-uid="C1.Zip.C1ZipFile.Open*"></a>
<h4 id="C1_Zip_C1ZipFile_Open_System_String_" data-uid="C1.Zip.C1ZipFile.Open(System.String)">Open(string)</h4>
<div class="markdown level1 summary"><p>Opens an existing zip file.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public void Open(string fileName)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Sub Open(fileName As String)</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></td>
      <td><span class="parametername">fileName</span></td>
      <td><p>The name of an existing zip file, including the path.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="C1_Zip_C1ZipFile_Open_System_String__remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>This method checks that the zip file exists and is a valid zip file, then
reads the zip file directory into the <a class="xref" href="C1.Zip.C1ZipFile.Entries.html#C1_Zip_C1ZipFile_Entries">Entries</a> collection.
The zip file is then closed, and can be used by other applications. There is no
need to close the zip file explicitly.</p>
</div>


<a id="C1_Zip_C1ZipFile_Open_" data-uid="C1.Zip.C1ZipFile.Open*"></a>
<h4 id="C1_Zip_C1ZipFile_Open_System_IO_Stream_" data-uid="C1.Zip.C1ZipFile.Open(System.IO.Stream)">Open(Stream)</h4>
<div class="markdown level1 summary"><p>Opens an existing zip file stored in a <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.io.stream">Stream</a>.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public void Open(Stream stream)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Sub Open(stream As Stream)</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.io.stream">Stream</a></td>
      <td><span class="parametername">stream</span></td>
      <td><p><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.io.stream">Stream</a> that contains a zip file.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="C1_Zip_C1ZipFile_Open_System_IO_Stream__remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>This method allows you to open and work with a zip file stored in a stream
instead of in an actual file.</p>
<p>Typical usage scenarios for this are zip files stored as application resources 
or in binary database fields.</p>
</div>
<h5 id="C1_Zip_C1ZipFile_Open_System_IO_Stream__examples">Examples</h5>
<p>The example below loads information from a zip file stored in an embedded resource. 
To embed a zip file in an application, follow these steps:</p>
<p>1) Right-click the project node in Visual Studio, select the <b>Add | Add Existing Item...</b> menu option.</p>
<p>2) Select a zip file to add to the project as an embedded resource.</p>
<p>3) Select the newly added file and make sure the <b>Build Action</b> property is set to "Embedded Resource".</p>
<pre><code class="lang-csharp">// get Stream from application resources
System.Reflection.Assembly a = this.GetType().Assembly;
using (Stream stream = a.GetManifestResourceStream("MyApp.test.zip"))
{
  // open C1ZipFile on the stream
  zip.Open(stream);

  // enumerate the entries in the zip file,
  foreach (C1ZipEntry ze in zip.Entries)
  {
    // show entries that have a 'txt' extension.
    if (ze.FileName.ToLower().EndsWith(".txt"))
    {
      using (var sr = new StreamReader(ze.OpenReader()))
      {
        MessageBox.Show(sr.ReadToEnd(), ze.FileName);
      }
    }
  }
}</code></pre>

</div>
