Example #1
0
        private void exportBytes(CVariable editvar)
        {
            var dlg = new SaveFileDialog();

            byte[] bytes = null;

            if (editvar is IByteSource)
            {
                bytes = ((IByteSource)editvar).Bytes;
            }

            dlg.Filter           = string.Join("|", ImportExportUtility.GetPossibleExtensions(bytes));
            dlg.InitialDirectory = Get().Configuration.InitialExportDirectory;

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                Get().Configuration.InitialExportDirectory = Path.GetDirectoryName(dlg.FileName);

                using (var fs = new FileStream(dlg.FileName, FileMode.Create, FileAccess.Write))
                {
                    using (var writer = new BinaryWriter(fs))
                    {
                        bytes = ImportExportUtility.GetExportBytes(bytes, Path.GetExtension(dlg.FileName));
                        writer.Write(bytes);
                    }
                    fs.Close();
                }
            }
        }
Example #2
0
        private void importBytes(CVariable editvar)
        {
            var dlg = new OpenFileDialog();

            dlg.InitialDirectory = Get().Configuration.InitialExportDirectory;

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                Get().Configuration.InitialExportDirectory = Path.GetDirectoryName(dlg.FileName);

                using (var fs = new FileStream(dlg.FileName, FileMode.Open, FileAccess.Read))
                {
                    using (var reader = new BinaryReader(fs))
                    {
                        var bytes = ImportExportUtility.GetImportBytes(reader);
                        editvar.SetValue(bytes);
                    }
                    fs.Close();
                }
            }
        }