Opens an existing zip file stored in a Stream.

Namespace:  C1.C1Zip
Assembly:  C1.Silverlight.Zip (in C1.Silverlight.Zip.dll)

Syntax

C#
public void Open(
	Stream stream
)
Visual Basic
Public Sub Open ( _
	stream As Stream _
)

Parameters

stream
Type: System.IO..::..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".

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

See Also