Ejemplo n.º 1
0
        private void ImportCSVData(CsvImportData importData)
        {
            // Show open file dialog box.
            OpenFileDialog openFileDialog = new OpenFileDialog
            {
                AddExtension    = true,
                CheckFileExists = true,
                CheckPathExists = true,
                DefaultExt      = ".csv",
                Filter          = "Comma-separated values (.csv)|*.csv",
                ValidateNames   = true
            };

            var result = openFileDialog.ShowDialog();

            if (result != true)
            {
                return;
            }

            // Open CSV file.
            try
            {
                using (var stream = openFileDialog.OpenFile())
                {
                    var streamReader = new StreamReader(stream);
                    var csvReader    = new CsvReader(streamReader);
                    csvReader.Configuration.Delimiter = importData != null
                                                            ? importData.Delimiter
                                                            : CsvImportData.DefaultDelimiter;
                    var importCsvDataWindow = new ImportCsvDataWindow(this.Context, csvReader, importData)
                    {
                        Owner = this
                    };
                    importCsvDataWindow.ShowDialog();
                }
            }
            catch (IOException e)
            {
                EditorDialog.Error("Unable to open CSV file", e.Message);
            }
        }
Ejemplo n.º 2
0
        private void ImportCSVData(CsvImportData importData)
        {
            // Show open file dialog box.
            OpenFileDialog openFileDialog = new OpenFileDialog
                {
                    AddExtension = true,
                    CheckFileExists = true,
                    CheckPathExists = true,
                    DefaultExt = ".csv",
                    Filter = "Comma-separated values (.csv)|*.csv",
                    ValidateNames = true
                };

            var result = openFileDialog.ShowDialog();

            if (result != true)
            {
                return;
            }

            // Open CSV file.
            try
            {
                using (var stream = openFileDialog.OpenFile())
                {
                    var streamReader = new StreamReader(stream);
                    var csvReader = new CsvReader(streamReader);
                    csvReader.Configuration.Delimiter = importData != null
                                                            ? importData.Delimiter
                                                            : CsvImportData.DefaultDelimiter;
                    var importCsvDataWindow = new ImportCsvDataWindow(this.Context, csvReader, importData)
                        {
                            Owner = this
                        };
                    importCsvDataWindow.ShowDialog();
                }
            }
            catch (IOException e)
            {
                EditorDialog.Error("Unable to open CSV file", e.Message);
            }
        }