PDF for UWP | ComponentOne
C1.C1Zip Namespace / C1ZipFile Class / Open Method
System.IO.Stream that contains a zip file.
Example

In This Topic
    Open Method
    In This Topic
    Opens an existing zip file stored in a System.IO.Stream.
    Syntax
    'Declaration
     
    
    Public Sub Open( _
       ByVal stream As Stream _
    ) 
    public void Open( 
       Stream stream
    )

    Parameters

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

    Example

    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);
          }
        }
      }
    }
    See Also