Exemplo n.º 1
0
        private void btImportUnzipMemoryStream_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog f = new OpenFileDialog();
                f.Filter = "Zip|*.zip";
                if (f.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }

                string file = f.FileName;

                using (MemoryStream ms = new MemoryStream())
                {
                    using (ZipStorer zip = ZipStorer.Open(file, FileAccess.Read))
                    {
                        List<ZipStorer.ZipFileEntry> dir = zip.ReadCentralDir();
                        zip.ExtractFile(dir[0], ms);

                        ms.Position = 0;
                        using (TextReader tr = new StreamReader(ms))
                        {
                            using (MySqlConnection conn = new MySqlConnection(Program.ConnectionString))
                            {
                                using (MySqlCommand cmd = new MySqlCommand())
                                {
                                    using (MySqlBackup mb = new MySqlBackup(cmd))
                                    {
                                        cmd.Connection = conn;
                                        conn.Open();

                                        mb.ImportFromTextReader(tr);

                                        conn.Close();
                                    }
                                }
                            }
                        }
                    }
                }
                MessageBox.Show("Finished.");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }