private void Form1_Load(object sender, System.EventArgs e) { // create DYMO COM objects DymoAddIn = new DymoAddInClass(); DymoLabels = new DymoLabelsClass(); // show the file name FileNameEdit.Text = DymoAddIn.FileName; // populate label objects SetupLabelObject(); // obtain the currently selected printer SetupLabelWriterSelection(true); }
private void printBtn_Click(object sender, EventArgs e) { try { DymoAddInClass _dymoAddin = new DymoAddInClass(); DymoLabelsClass _dymoLabel = new DymoLabelsClass(); // this call returns a list of objects on the label string[] objNames = _dymoLabel.GetObjectNames(false).Split(new Char[] { '|' }); // Create OpenFileDialog OpenFileDialog dlg = new OpenFileDialog(); dlg.DefaultExt = ".zip"; dlg.Filter = "ZIP Files (.zip)|*.zip"; dlg.ShowDialog(); // Open document string filename = dlg.FileName; // Get the file path to use string thePath = System.IO.Path.GetDirectoryName(dlg.FileName); ZipFile zf = null; // Open the stream FileStream fs = File.OpenRead(filename); zf = new ZipFile(fs); // List that will hold all the files found in the ZIP List <string> Files = new List <string>(); //Loop over the files foreach (ZipEntry zipEntry in zf) { if (!zipEntry.IsFile) { continue; } String entryFileName = zipEntry.Name; // to remove the folder from the entry:- entryFileName = Path.GetFileName(entryFileName); // Optionally match entrynames against a selection list here to skip as desired. // The unpacked length is available in the zipEntry.Size property. byte[] buffer = new byte[4096]; // 4K is optimum Stream zipStream = zf.GetInputStream(zipEntry); // Manipulate the output filename here as desired. String fullZipToPath = Path.Combine(thePath, entryFileName); string directoryName = Path.GetDirectoryName(fullZipToPath); if (directoryName.Length > 0) { Directory.CreateDirectory(directoryName); } // Unzip file in buffered chunks. This is just as fast as unpacking to a buffer the full size // of the file, but does not waste memory. // The "using" will close the stream even if an exception occurs. using (FileStream streamWriter = File.Create(fullZipToPath)) { StreamUtils.Copy(zipStream, streamWriter, buffer); Files.Add(fullZipToPath); } } for (int i = 0; i < Files.Count; i++) { if (_dymoAddin.Open(Files[i])) { _dymoAddin.Print(1, false); } } if (zf != null) { zf.IsStreamOwner = true; // Makes close also shut the underlying stream zf.Close(); // Ensure we release resources } } catch (Exception) { throw; } }
private void Form1_Closed(object sender, System.EventArgs e) { // clean up DYMO COM objects DymoAddIn = null; DymoLabels = null; }