C1.C1Zip Namespace > C1ZipFile Class > Open Method : Open(Stream) Method |
'Declaration
Public Overloads Sub Open( _ ByVal stream As System.IO.Stream _ )
public void Open( System.IO.Stream stream )
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.
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); } } } }
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2