[]
        
(Showing Draft Content)

C1.Zip.C1ZipFile.Open

Open Method

Open(string)

Opens an existing zip file.

Declaration
public void Open(string fileName)
Parameters
Type Name Description
string fileName

The name of an existing zip file, including the path.

Remarks

This method checks that the zip file exists and is a valid zip file, then reads the zip file directory into the Entries collection. The zip file is then closed, and can be used by other applications. There is no need to close the zip file explicitly.

Open(Stream)

Opens an existing zip file stored in a Stream.

Declaration
public void Open(Stream stream)
Parameters
Type Name Description
Stream stream

Stream that contains a zip file.

Remarks

This method allows you to open and work with a zip file stored in a stream instead of in an actual file.

Typical usage scenarios for this are zip files stored as application resources or in binary database fields.

Examples

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:

1) Right-click the project node in Visual Studio, select the Add | Add Existing Item... menu option.

2) Select a zip file to add to the project as an embedded resource.

3) Select the newly added file and make sure the Build Action property is set to "Embedded Resource".

// 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);
      }
    }
  }
}